Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Date difference between each row

Hi COmmunity,

 

I'm fairly new to talend, and i'm trying to get datedifference between each row of a table.  Example:

IDStatusTimestamp
1ON2017-05-26 19:12
2OFF2017-05-26 20:55
3ON2017-05-26 23:28
4OFF2017-05-27 05:35
5ON2017-05-27 07:01

 

 

I need to create a fact table with the difference between each row, so i can know how much "ON" time the machine is having.  I've tried the diffdate in tmap component, but i cannot find a way to calculate that time.  Can someone with experience help me throught it?

 

Thanks,

Dany

Labels (2)
1 Reply
Anonymous
Not applicable
Author

An easier way of achieving this would be to convert the dates into milliseconds (get a Date object and call getTime()) and subtract one from the other. Then you can carry out the maths on the remainder.

 

For example, if the difference between the dates comes to  6543892716, then the difference is calculated below...

 

6543892716/1000 = 6543892.716 seconds

6543892.716/60 = 109064.8786 minutes

109064.8786/60 = 1817.747976666 hours

1817.747976666/24 = 75.73949902777 days

 

0.73949902777*24 = 17 hours

0.747976666666*60 = 44 mins

0.8786*60 = 52 seconds

0.716*1000 = 716 milliseconds

 

So that equates to 75 days, 17 hours, 44 mins, 52 seconds and 716 milliseconds

I stepped through that in a long winded fashion, you can cut corners using a modulus operation or two 🙂