Five Stars

Convert Time in string format to 24 hour format

Hello Everyone,

 

Need help on this !!

 

I am trying to convert a time of type string into a date of 24 hour format.

 

Input string : "11:59:00 PM"

Tmap Expression : "TalendDate.parseDate("HH:mm:ss", row6.Start_Time) 

Output date 11:59:00.0000000

Expected: 23:59:00.0000000

 

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Ten Stars

Re: Convert Time in string format to 24 hour format

"HH" in a date format string implies 24 hour time. If you have AM/PM in your strings, use "hh".

As for the output, once your string is converted to a Date object, you can format the output however you want. If you need to print the date, you can use TalendDate.formatDate() for that. You can also influence the output format by setting the Date Pattern for that column in your schema. In that case, you'd want the pattern to be "HH:mm:ss" to print 24 hour time.
4 REPLIES
Ten Stars

Re: Convert Time in string format to 24 hour format

Your date pattern needs to be "hh:mm:ss a" to capture the AM/PM designation.
Five Stars

Re: Convert Time in string format to 24 hour format

Thank you for your reply. I tried that and it still doesn't convert to 24 hour format.

TalendDate.parseDate("HH:mm:ss a",row3.Start_Time )

Ten Stars

Re: Convert Time in string format to 24 hour format

"HH" in a date format string implies 24 hour time. If you have AM/PM in your strings, use "hh".

As for the output, once your string is converted to a Date object, you can format the output however you want. If you need to print the date, you can use TalendDate.formatDate() for that. You can also influence the output format by setting the Date Pattern for that column in your schema. In that case, you'd want the pattern to be "HH:mm:ss" to print 24 hour time.
Five Stars

Re: Convert Time in string format to 24 hour format

worked !! Missed that in your first note Smiley Happy Thank you so much. Appreciate it.