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.
Calculate the difference in seconds for two timestamps field
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.