Derriving difference of two timestamps

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
bharatagnihotri
Participant
Posts: 7
Joined: Thu Sep 30, 2004 5:22 am

Derriving difference of two timestamps

Post by bharatagnihotri »

Hi,

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

Any ideas are welcome
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
T42
Participant
Posts: 499
Joined: Thu Nov 11, 2004 6:45 pm

Post 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
bharatagnihotri
Participant
Posts: 7
Joined: Thu Sep 30, 2004 5:22 am

Post 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"
Post Reply