Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
yohanhwang
Frequent Visitor

datetime not converting correctly when running python script

Hi.

 

So I get an error that says:

 

DataSource.Error: ADO.NET: Python script error.
<pi>ValueError: time data 'Microsoft.OleDb.Date' does not match format '%m/%d/%Y'
</pi>

 

when running the following portion of my python script in power query editor:

 

result = []
for value in dataset["elcn_contributiondate"]:
    if (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2018,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y')<= datetime.datetime.now() - relativedelta(years=4)):
        result.append('FY2018')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2019,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y')<= datetime.datetime.now() - relativedelta(years=3)):
        result.append('FY2019')
    elif (datetime.strptime(value, '%m/%d/%Y')>= pd.Timestamp(2020,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now() - relativedelta(years=2)):
        result.append('FY2020')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2021,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now() - relativedelta(years=1)):
        result.append('FY2021')
    elif (datetime.strptime(value, '%m/%d/%Y') >= pd.Timestamp(2022,7,1,12)) & (datetime.strptime(value, '%m/%d/%Y') <= datetime.datetime.now()):
        result.append('FY2022')
    else:
        result.append('no year')
dataset['FY'] = result

 No matter what other version of datetime I try it still errors out. Any help would be greatly appreciated.

0 REPLIES 0

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.