Calculate the difference in seconds for two timestamps field

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
jiegao
Premium Member
Premium Member
Posts: 46
Joined: Fri Sep 22, 2006 6:12 pm

Calculate the difference in seconds for two timestamps field

Post by jiegao »

Hi.
I am wondering what is the best way to calcuate the difference in seconds for two timestamps fields in Server job. Thanks in advance.
Regards
Jie
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Server jobs don't have a timestamp data type, so you would need to separate the date and time portions of the string, then use ICONV to convert the two parts, perform the delta math, the use OCONV again to build the timestamp.
jiegao
Premium Member
Premium Member
Posts: 46
Joined: Fri Sep 22, 2006 6:12 pm

Post by jiegao »

Thanks
Regards
Jie
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Something like this will do the task. Error handling has been omitted for clarity.

Code: Select all

FUNCTION TimestampDiff(Timestamp1,Timestamp2)
Day1 = Field(Timestamp1, " ", 1, 1)
Day2 = Field(Timestamp2, " ", 1, 1)
Time1 = Field(Timestamp1, " ", 2, 1)
Time2 = Field(Timestamp2, " ", 2, 1)
Seconds1 = Iconv(Time1, "MT") + 86400 * Iconv(Time1, "DYMD")
Seconds2 = Iconv(Time2, "MT") + 86400 * Iconv(Time2, "DYMD")
Ans = Seconds2 - Seconds1
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply