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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.