Date parsing

Hi,

I extract data from a website and save it in a datatable. The date formatting is then like this:

Tuesday, 14-FEB-2023
Saturday, 18-FEB-2023
Sunday, 19-FEB-2023
Sunday, 19-FEB-2023
Tuesday, 07-MAR-2023
Tuesday, 07-MAR-2023
Friday, 10-MAR-2023
Friday, 10-MAR-2023
Monday, 13-MAR-2023
Monday, 13-MAR-2023

I am using this code in a for each row activity to change the formatting to dd/mm/yyyy:

DateTime.ParseExact(Currentrow(“Date”).Tostring,“dddd, dd-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yy/MM/dd”)

However, this is producing this result:

23/02/2014
23/02/2018
23/02/2019
23/02/2019
23/03/2007
23/03/2007
23/03/2010
23/03/2010
23/03/2013
23/03/2013

This is not exactly correct, so I guess I have something wring in the code. Any suggestions?

@Evert_Randers

Please try like this

DateTime.ParseExact(Currentrow("Date").Tostring,"dddd, dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("'yy/MM/dd")

Looks like excel is reading the date in dd/MM/yy format so I added a literal(') in to string to make it a text

Also if you want to change format to dd/mm/yyyy then use this

DateTime.ParseExact(Currentrow("Date").Tostring,"dddd, dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

cheers

@Evert_Randers ,
You can also try this one
(Assuming your whole “Tuesday, 14-FEB-2023” is in single column)

DateTime.ParseExact(Split(Currentrow("Date").Tostring,", ")(1),"dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("yy/MM/dd")

Regards,

Excellent, thank you very much!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.