Have to parse date in this format "Aug 7, 2023, 2:50:45 PM"

So basically I’m extracting some data from a json and one of the data is a date. As you can see it comes in a weird format and I dont know how to parse it to a timesapam variable in a clean way (not with a bunch of cases in a switch for example).

Do someone find out an interesting solution?

Hi @Pelayo_Celaya_Fernandez

Try this:

ParsedDateTime=DateTime.ParseExact(InputDateString, "MMM d, yyyy, h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss")

Output of ParsedDateTime is String.

TimeParsedValue= TimeSpan.Parse(ParsedDateTime.ToString)

Output of TimeParsedValue is System.TimeSpan

Hope it helps!!

1 Like

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