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

Calculate Time Difference in HH:mm:ss

why it is such a difficult thing to calculate time difference in talend.

i have two columns as Output and Input.

I am trying to calcualte the total hours by calculting difference between these Output-Input.

I did tried Datediff in talend. but it wont give me the direct value in HH:MM, it gives in HH, or mm or ss, but not in HH:mm

Then i have to use some mathemetical calculations to get the actual minutes so that i can concatenate these minutes values and seconds values.

 

Why cant there is jus a simple function where it gives me exact difference value in HH:mm,

why such long process?

 

Labels (2)
1 Reply
Anonymous
Not applicable
Author

What if your requirement was "yyyy-dd", or "MM-mm", or "yyyy-SSS", or "dd-HH"....see where I am going with this? This is a Java issue you have, not a Talend issue. Talend *could* build a routines with all of the permutations (some of which are shown above), but that would be A LOT of permutations.

 

The way to achieve your goal is to write your own routine to achieve your requirement. Below is some code which shows an example of how you can work out seconds, minutes and hours between two dates. You should be able to extrapolate from that....

Date date1 = routines.TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2018-01-01 12:09:12");
Date date2 = routines.TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", "2018-01-02 12:09:11");

long orig_ss = routines.TalendDate.diffDate(date1, date2, "ss");
long ss = orig_ss%60;
long orig_mm = orig_ss/60;
long mm = orig_mm%60;
long HH = orig_mm/60;

System.out.println("Second:"+ss);
System.out.println("Minutes:"+mm);
System.out.println("Hours:"+HH);