Date calculation

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
etlgeek
Participant
Posts: 3
Joined: Sat Nov 10, 2007 7:47 am

Date calculation

Post by etlgeek »

Hi

I have two timestamps in the format yyyy-mm-dd hh24:mi:ss.
I want to find the exact difference (sec level). I am doing below code, but is only giving me the difference in number of days not up to the HH:MM:SS level. Can someone help me to modify the code?

code
Iconv(Field(date1," ",1),"D-YMD[4,2,2]") - Iconv(Field(date2," ",1),"D-YMD[4,2,2]")


date1 - date2

example:
2007-11-10 00:05:44 - 2007-10-26 09:50:42

results i am getting : 15 (days)

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's alot more complicated than that. Split the timestamp and convert all four pieces. Then (Days * 24 * 60 * 60) + net time difference.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If you'd rather not have the joy of working this out for yourself, there is some code posted here you might find useful. :wink:

Oh, and welcome! :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
etlgeek
Participant
Posts: 3
Joined: Sat Nov 10, 2007 7:47 am

Post by etlgeek »

Thanks Chulett for quick reply. That routine looks more complicated. so if i modify the code as below to get the results in hours instead of no of days. does it give correct results in hours?

(Iconv(Field(source.COMPLETED_DATE," ",1),"D-YMD[4,2,2]") - Iconv(Field(source.ENTERED_DATE," ",1),"D-YMD[4,2,2]") )*24

for the same example i am getting 360.

Thanks
etlgeek
Participant
Posts: 3
Joined: Sat Nov 10, 2007 7:47 am

Post by etlgeek »

Thanks Chulett for quick reply. That routine looks more complicated. so if i modify the code as below to get the results in hours instead of no of days. does it give correct results in hours?

(Iconv(Field(source.COMPLETED_DATE," ",1),"D-YMD[4,2,2]") - Iconv(Field(source.ENTERED_DATE," ",1),"D-YMD[4,2,2]") )*24

for the same example i am getting 360.

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

Post by ray.wurlod »

You need to multiply by 24 after performing the subtraction. DataStage complies with the usual rules for arithmetic operator precedence.
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