Convert String to Specified Format

Hi Guys,

I have a String Like this “20203107” which Represents yyyy as 2020, dd as 31 , MM as 07. so How to Convert that String into mm/dd/yyyy Format?

@kuldeep.shinde

Please try this

Datetime.ParseExact("20203107","yyyyddMM",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

cheers

it Gives Below Error:

Assign: String ’ 20203107’ was not recognized as a valid DateTime.

@kuldeep.shinde

I see a space in your string at the start…if its a variable…use .Trim

stringvar.Trim

cheers

Thanks @Anil_G It Works:)

1 Like

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