Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to convert 12 Hour Time to 24 Hour Time date

I have a text file that has a string column with a datetime formatted as "MM/dd/yyyy HH:mm:ss aa" or "02/18/2009 03:30:00 AM"
I am trying to extract the Time and convert it to a 24 Hour Date field.
So far in Tmap I have used the following syntax to extract the time data as a date field but it is still in a 12 hour format. Is there any way to convert it to 24 hour format?

TalendDate.parseDate("HH:mm:ss aa",TalendDate.formatDate("HH:mm:ss aa",TalendDate.parseDate("MM/dd/yyyy HH:mm:ss aa",row2.Last_Connect)))
Labels (2)
9 Replies
Anonymous
Not applicable
Author

Hi
I got this to work :-
Input column - 'Date' datatype
Input column date pattern = "MM/dd/yyyy hh:mm:ss a"
Input value = 02/18/2009 11:30:00 PM
tMap expression variable var1 - 'Date' datatype
Output column - 'Date' datatype
Output column date pattern = "MM/dd/yyyy HH:mm:ss"
Output value = 02/18/2009 23:30:00
HTH
Anonymous
Not applicable
Author

Thanks but when the input data type is String this does not seem to work. Any other suggestions?
Anonymous
Not applicable
Author

It seems that no matter what I try use Talend.ParseDate against a STRING in the format of "MM/dd/yyyy HH:mm:ss aa" or "2/12/2009 02:12:00 PM" it converts the date to AM.
I have tried this numerous ways. Am I missing something?
TalendDate.parseDate("MM/dd/yyyy HH:mm:ss aa",row2.Last_Connect)
Anonymous
Not applicable
Author

Hi,
Try :-
Input column - 'String' datatype
Input value = 02/18/2009 11:30:00 PM
tMap expression variable var1 - 'Date' datatype
Expression = new Date(row2.Last_Connect)
Output column - 'Date' datatype
Output column date pattern = "MM/dd/yyyy HH:mm:ss"
Output value = 02/18/2009 23:30:00
Anonymous
Not applicable
Author

Thanks Works Great!
Anonymous
Not applicable
Author

TalendDate.getPartOfDate("HOUR",TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",TalendDate.formatDate("yyyy-MM-dd hh:mm:ss",row1.HOUR)))
can anyone help me out please what wrong in this code, i am trying to fetch 24hrs day format from the above code.
Anonymous
Not applicable
Author

My output looks like 0 to 12 here is in below , my requirement is the HOUR column have to be 0 to 24 like minutes 0 to 59.
I am new to Talend and i did not find any documentation  forum how to convert the time format to 24 hrs
Anonymous
Not applicable
Author

Hi srikant.panda57,
TalendDate.getPartOfDate("HOUR",TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",TalendDate.formatDate("yyyy-MM-dd hh:mm:ss",row1.HOUR)))

Could you please give us your input column? Is it "Date" type?
Elaborating your case with an example with input and expected output values will be preferred.

The method should be: TalendDate.getPartOfDate(String, Date):int
Best regards
Sabrina
Anonymous
Not applicable
Author

Hello Geeks,
Please help I am struggling , new to talend
I have a input string as utcStartTime which has a value 1443696342801
I want to convert this into date
something like this : 01-01-1970 11:52:39

tried many things 
new java.util.Date(Long)(row1.HIREDATEe*1000))
but still unable to do so
PLease helppp me
many thanks