Timestamp addition

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
bhalachandra
Participant
Posts: 1
Joined: Thu Jun 17, 2004 1:51 am

Timestamp addition

Post by bhalachandra »

Hi ,
I am new to datastage. Is there a function or a transform that helps in addition of timestamps. I have a timestamp "2004-06-13 22:30:08". For this I need to add 7 hours and get the timestamp "2004-06-14 05:30:08". Can you please suggest me a way to do this.

Thanks in advance,
Bhalachandra
denzilsyb
Participant
Posts: 186
Joined: Mon Sep 22, 2003 7:38 am
Location: South Africa
Contact:

Post by denzilsyb »

Hallo Balachandra

use the Iconv function to convert the timestamp into an internal format, then add the 7 hours and then oconv the internal number to a timestamp again. (the help documents iconv/oconv quite well)

dnzl
dnzl
"what the thinker thinks, the prover proves" - Robert Anton Wilson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard! :D

You have two choices; you can convert to internal date and time formats and perform the arithmetic then convert back to timestamp format, or you can deal with the substrings in the timestamp and perform the arithmetic on these. The latter works because there are effectively no data types while data are in DataStage.

Code: Select all

Delta = 7
DatePart = Iconv(TheData[1,10], "DYMD")
TimePart = Iconv(TheData[12,8], "MT")  ; * seconds since midnight
TimePart += (Delta * 3600)
If TimePart > 86400
Then
   TimePart -= 86400
   DatePart += 1
End
Ans = Oconv(DatePart, "D-YMD[4,2,2]") : " " : Oconv(TimePart, "MTS:")

Code: Select all

Delta = 7
Hours = TheData[12,2]
If Hours < (24 - Delta)
Then
   TheData[12,2] = Fmt(Hours + Delta, "R%2")
End
Else
   TheData[12,2] = Fmt(Hours + Delta - 24, "R%2")
   TheData[9,2] = Fmt(TheData[9,2] + 1, "R%2")
End
Ans = TheData
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