Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi COmmunity,
I'm fairly new to talend, and i'm trying to get datedifference between each row of a table. Example:
ID | Status | Timestamp |
1 | ON | 2017-05-26 19:12 |
2 | OFF | 2017-05-26 20:55 |
3 | ON | 2017-05-26 23:28 |
4 | OFF | 2017-05-27 05:35 |
5 | ON | 2017-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
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 🙂