Date coversion problem

Hi Team,.

I am getting an error - String was not recognized as a valid date time

Extracting date from an application its format is
Sep 15, 2022 8:25 AM - Storing in a String variable(Test1)

While conversion i am getting this error
Test2(Datetime variable) = DateTime.ParseExact(Test1,“MMM dd, yyyy hh:mm tt”, System.Globalization.CultureInfo.InvariantCulture)

@Robotics
System.Datetime.ParseExact(DateTimeStr,“MM/dd/yyyy HH:mm:tt”,New system.Globalization.CultureInfo(“en-US”)).ToString(“MM-dd-yyyy HH-mm”)

Try with this and simple store in string variable

Hi,

Can you try as the following? (Modified “hh” to “h”)

Test2(Datetime variable) = DateTime.ParseExact(Test1,"MMM dd, yyyy h:mm tt", System.Globalization.CultureInfo.InvariantCulture)

Regards,

image
yellow represent you are getting and red represent you want to convert

Hi @Robotics

How about this expression?

DateTime.ParseExact("Sep 15, 2022 8:25 AM","MMM dd, yyyy h:mm tt",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy") "09/15/2022"

image

Regards
Gokul

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