String to Date Format

Hi All, need help in converting a string to required format which can be a string or date format as well

I have “19-MAY-2020” as a string and I want to convert either to date or string type which is 2020-05-19 when I use the below expression it is giving below error
Assign: String was not recognized as a valid DateTime

Expression:
DateTime=Date.ParseExact(“19-MAY-2020”, “yyyy-mm-dd”,CultureInfo.InvariantCulture)

ReqOutput: 2020-05-19 (String or Date)

Hi, used
Str var=CDate( Date_).ToString(“yyyy-MM-dd”)

1 Like

Hi,

Can you try the following expression?

Date.ParseExact("19-MAY-2020", "dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture).toString("yyyy-MM-dd")

This returns string type

Regards,

2 Likes

I used this CDate("19-MAY-2020”).ToString(“yyyy-MM-dd”) and it is working as expected what if the same output should be Date Format ?

Hi @vboddu
Can you please check this Post might Help you,

Thanks
Latika

1 Like

@Yoichi it worked for “19-MAY-2020” but not for “9-MAY-2020” what if I need date type?

1 Like

Hi,

The following returns DateTime type.

Date.ParseExact("19-MAY-2020", "dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture)

Regards,

Date.ParseExact(“19-MAY-2020”, “d-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).toString(“yyyy-MM-dd”)

This worked :slight_smile:

1 Like

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