Page 1 of 1

Date calculation

Posted: Sat Nov 10, 2007 8:18 am
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

Posted: Sat Nov 10, 2007 8:55 am
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.

Posted: Sat Nov 10, 2007 9:42 am
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

Posted: Sat Nov 10, 2007 10:50 am
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

Posted: Sat Nov 10, 2007 10:52 am
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

Posted: Sat Nov 10, 2007 1:28 pm
by ray.wurlod
You need to multiply by 24 after performing the subtraction. DataStage complies with the usual rules for arithmetic operator precedence.