Convert date stocked in string value to "yyyy-MM-dd" Format

Hello ,
I have a date value retrieved from a text and the format of this value is not specific it may be “dd-MM-yyyy” , “dd-MM-yyyy” or other format ,i need to compare this value with a date value retrived from Excel this date is in this format “yyyy-MM-dd” so i tried to convert the first value into excel date format with the expression mentioned in the pic bellow but it deos not work.

Any help please ?
Thanks.


Hi,

It’s enecessary to set CultureInfo as 3rd argument like the following. Can you try this?

DateTime.ParseExact("2022-11-20",{"yyyy-MM-dd"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString

OR

DateTime.ParseExact("2022-11-20",{"yyyy-MM-dd"},System.Globalization.CultureInfo.InvariantCulture).ToString

Regards,

1 Like

Hi, it involves a bit of work but getting that date using regex may be a solution.

1 Like

Hi @Deep_HML

Check out this expression

DateTime.ParseExact(YourString,{"dd-MM-yyyy","dd-MM-yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")

Regards
Gokul

1 Like

HI @Deep_HML

You have missed

System.Globalization.CultureInfo.InvariantCulture

In your expression this should be added after adding the array of formats

Regards
Sudharsan

1 Like

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