How to convert 12 Hour Time to 24 Hour Time date

One Star

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)))
One Star

Re: How to convert 12 Hour Time to 24 Hour Time date

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
One Star

Re: How to convert 12 Hour Time to 24 Hour Time date

Thanks but when the input data type is String this does not seem to work. Any other suggestions?
One Star

Re: How to convert 12 Hour Time to 24 Hour Time date

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)
One Star

Re: How to convert 12 Hour Time to 24 Hour Time date

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
One Star

Re: How to convert 12 Hour Time to 24 Hour Time date

Thanks Works Great!

Re: How to convert 12 Hour Time to 24 Hour Time date

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.

Re: How to convert 12 Hour Time to 24 Hour Time date

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
Moderator

Re: How to convert 12 Hour Time to 24 Hour Time date

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
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars ami
Five Stars

Re: How to convert 12 Hour Time to 24 Hour Time date

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