Page 1 of 1

Derriving difference of two timestamps

Posted: Wed Dec 29, 2004 10:16 am
by bharatagnihotri
Hi,

We are trying to derive difference between two timestamps(in hours)

Any ideas are welcome

Posted: Wed Dec 29, 2004 2:23 pm
by ray.wurlod
Welcome aboard! :D

There is no built-in operator for this task; you probably have to construct your own. Do you need whole hours or fractional? If whole hours, is this a rounded or truncated number? (A truncated number would be "completed hours".)

Basically you have to pick apart each timestamp, convert all the pieces to a common format (seconds is recommended), perform the arithmetic, and assemble the result.

Because you're in a parallel job, you would do this in a BuildOp (refer to Chapter 55 of the Parallel Job Developer's Guide for more information).

Posted: Wed Dec 29, 2004 10:18 pm
by T42
In a transformer:

Code: Select all

((JulianDayFromDate(TimestampToDate(Input.currentTime)) * 24) + (HoursFromTime(TimestampToTime(Input.currentTime)))) - ((JulianDayFromDate(TimestampToDate(Input.oldTime)) * 24) + (HoursFromTime(TimestampToTime(Input.oldTime))))
This should get you started using truncated hours. It does not deal with differences with regards to minutes, or anything like that.

The field using this code needs to be an integer.

That was fun making this. :P

Posted: Thu Dec 30, 2004 2:10 am
by bharatagnihotri
Thanks,

But in the meanwhile we got some other solution to achieve the same.

We defined a stage variable and defined it as decimal , the derivation of which is as follows..

DFloatToDecimal(SecondsSinceFromTimestamp(INPUT_TIMESTAMP,CURRENT_TIMESTAMP))

It is working fine.......



"FEEDBACK IS THE BREAKFAST OF CHAMPIONS"