How to convert date from full letters to numbers and put it into a certain format

Hi guys,

How would you convert for example September 5, 2015 to 20150905.

(September 5, 2015 is a string rather than a date format right now)

Appreciate your help!

Create a DateTime variable, mine is called dt.

Assign
dt = DateTime.Parse(“September 15, 2015”)

Log
dt.ToString(yyyyMMdd)

1 Like

Hi @ianhyj,

As you told september 5, 2015 is a string variable, you can use the below expression in write line or in assign statement.

Datetime.ParseExact(“September 5, 2015”,“MMMM d, yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyyMMdd”)

The output of the above expression is a string, if you want to convert it to datetime you can do it by surrounding it by convert.todatetime(The whole above expression)

1 Like

@ianhyj,

Try Below one:

Datetime.parseexact(“January 05 2019”,“MMMM dd yyyy”,system.gobalization.cultureinfo.invariantculture).tostring(“yyyyMMdd”)

Thank you so much for this!

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