Time is in string format with AM and PM i need to convert time in 24 hrs format


I am having a string which is having time like “7:00 PM”. I need to convert this in 24 hrs format. I tried below thing.

Datetime.ParseExact(startTime,“hh:mm tt”,new system.Globalization.CultureInfo(“en-US”)).ToString(“HH:mm”) getting below error.

Error - Assign: String was not recognized as a valid DateTime.

How to resolve this.

as it is 1 digit we would use h instead of hh

Getting Issue.

use the immediate panel and show us the variable value, thanks

We do see, that it is working

give a try by trimming the value

Datetime.ParseExact(YourStringVar.Trim(),"h:mm tt", System.Globalization.CultureInfo.InvariantCulture).toString("HH:mm")
1 Like

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