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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.