Converting A DateTime String to DateTime regardless of format

Hi There,

I have the following string : 10/6/2023 6:49:36 AM

And am trying to convert to datetime VAR to compare, trying to use the following:

DateTime.ParseExact(CurrentRow(“Date/Time”).Tostring, “dd/MM/yyyy hh:mm:ss tt”, System.Globalization.CultureInfo.InvariantCulture)

This does not work due to no “06” for month or “06” for hour, so I’m wondering if it’s possible in one statement to account for both M And MM, and hh And h? Similarly dd and mm/ss

Much appreciated

@Kyleb91

arr_dateformats={“dd/MM/yyyy hh:mm:ss tt”,““dd/MM/yyyy hh:mm:ss tt”,”“dd/M/yyyy h:mm:ss tt”)

DateTime.ParseExact(CurrentRow(“Date/Time”).Tostring,arrdatefromats,System.Globalization.CultureInfo.InvariantCulture)

arr_dateformats is the array of type string variable

you can add as many formats you want

cheers

1 Like

You can try this:

DateTime.ParseExact(CurrentRow("Date/Time").Tostring, {"dd/MM/yyyy hh:mm:ss tt", "d/M/yyyy h:mm:ss tt"}, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None)
1 Like

Kindly note: a
as mentioned by others tt is to use:

1 Like

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