Date difference between each row

One Star

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

Community Manager

Re: Date difference between each row

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 :-)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

APIs for Dummies

View this on-demand webinar about APIs....

Watch Now