cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Datetime with AM/PM to 24Hr date format

anubhav_nautiya
Contributor

Hi, I have a requirement where from the source file. I am getting date as string value ‘10/21/2019 6:16:54 PM’, I want the date to be converted into yyyy-mm-dd hh:mm:ss format.
In the example given above the output should be ‘2019-10-21 18:16:54’.
8/3/2019 4:24:00 AM for this input output should be 2019-08-03 04:24:00
for 7/3/2019 12:09:45 PM output should be 2019-07-03 12:09:45

I was able to achieve this using a complex regex but if anyone has a better way to do this please reply to this thread.

Regards
Anubhav

1 ACCEPTED SOLUTION

Hi Chris,
Thanks for your inputs, I was able to achieve this by using the expression below,
Date.parse($dt,‘MM/dd/yyyy h:m:s a’).toLocaleDateTimeString({“format”:“yyyy-MM-dd HH:mm:ss”})

Regards
Anubhav

View solution in original post

5 REPLIES 5

Hi Chris,
Thanks for your inputs, I was able to achieve this by using the expression below,
Date.parse($dt,‘MM/dd/yyyy h:m:s a’).toLocaleDateTimeString({“format”:“yyyy-MM-dd HH:mm:ss”})

Regards
Anubhav