One Star

[resolved] Adding 2 Dates

Hi,
                I want to add 2 dates which are coming in my input along with time.
My Input is
2015-02-26 08:00:00   1900-01-01 09:00:00

My Output should be
2015-02-26 17:00:00
In my output my date should be same which is coming from first column.
Thanks In advance
Lmit 
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Adding 2 Dates

Hi Lmit,
Try the following approach:
1. Separate the 2 dates to be added; the 1st one would be of the format "yyyy-MM-dd HH:mm:ss" & the 2nd one of "HH:mm:ss"
2. Now extract the Hour, Minute & Seconds part from the 2nd date, & convert it to Integer format.
3. Then use something like this:
TalendDate.addDate(TalendDate.addDate((TalendDate.addDate(Var.base_time,"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_hh,"HH")),"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_mm,"mm"),"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_ss,"ss")  

This would add Hours, as well as Minutes, as well as Seconds.
Hope this should work for you. Smiley Happy
MathurM
4 REPLIES
Community Manager

Re: [resolved] Adding 2 Dates

Get respectively the hours, minutes and seconds of the second date, for example,
tFileInputDelimited--main--tJavaRow--main--tMap....
on tJavaRow
context.hours=row1.secondColumnName.getHours();
context.minutes....

Then, add hours, minutes and seconds to the first date using built-in function on tMap, for example:
TalendDate.addDate(row1.firstColumnName,context.hours,"HH")

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Adding 2 Dates

Thanks for your reply Shong...I need to consider Minutes and Seconds also.how can i get it?
My Input
2015-02-26 08:20:00 1900-01-01 09:40:00
Output 
2015-02-26 17:60:00.
Minutes and seconds also need to get added
Thanks In Advance
Lmit
One Star

Re: [resolved] Adding 2 Dates

Hi Lmit,
Try the following approach:
1. Separate the 2 dates to be added; the 1st one would be of the format "yyyy-MM-dd HH:mm:ss" & the 2nd one of "HH:mm:ss"
2. Now extract the Hour, Minute & Seconds part from the 2nd date, & convert it to Integer format.
3. Then use something like this:
TalendDate.addDate(TalendDate.addDate((TalendDate.addDate(Var.base_time,"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_hh,"HH")),"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_mm,"mm"),"yyyy-MM-dd HH:mm:ss",Var.tobeadded_time_ss,"ss")  

This would add Hours, as well as Minutes, as well as Seconds.
Hope this should work for you. Smiley Happy
MathurM
One Star

Re: [resolved] Adding 2 Dates

I performed the whole operation in a tMap (you can work with any other component of your choice)
The following is the output