Page 1 of 1

Date subtraction into seconds

Posted: Tue Jan 30, 2007 8:11 am
by rayx0063
I was wondering if anyone has some experience with getting the sysdate out of datstage ,Timedate() function, and then subtracting the two dates to get the total seconds between the 2 dates.

Something like this
Seconds_between =( Iconv('01:20:00',"MTS") + (Date() +1 ) - Iconv(TimeDate(),"MTS"@VM"D DMY[2,A3,4]") )

sleep(Seconds_between)


Note: 1.) I do know that DS converts this to its internal number, its a example.
2.) I can do this in oracle, but I didn't want to write it out to a file and then have to open/read/.... the file into DS.

Posted: Tue Jan 30, 2007 8:16 am
by DSguru2B
Are the two dates in timestamp format ? You can certainly write a routine. Extract the date part, get the internal format which is number of days, multiply that with 24*60*60 to get number of seconds. Add that to the ICONV of time which will be number of seconds since Jan 1st 1968 12:00 AM. Get both your timestamps in that format, do your substraction. This will give you the difference in seconds.

Posted: Tue Jan 30, 2007 8:21 am
by chulett
You could also find any post by kcbland register at his site and download their free utilities. One of which does this timestamp difference.

Posted: Tue Jan 30, 2007 8:55 am
by DSguru2B
You mean KBATimestampDeltaSecondsroutine.

Posted: Tue Jan 30, 2007 9:09 am
by rayx0063
Thanks, i was just over looking a couple of things... I should look like this.

SecondsBetween =(Iconv('01:20:00',"MTS") + (Iconv( (Date() +1),"D DMY")*86400 )) - (Int(Time()) + (Iconv(Date(),"D DMY")*86400 ))

Posted: Tue Jan 30, 2007 9:14 am
by DSguru2B
Date() and Time() will give you date and time in internal formats, respectively. You dont need to ICONV them again. All you need is

Code: Select all

SecondsBetween = (Iconv('01:20:00',"MTS") + (Date() +1)*86400 ) - (Time() + (Date())*86400 )

Posted: Tue Jan 30, 2007 10:05 am
by rayx0063
Correct, I don't need the extra Iconv, But the Int(time()) should be added to remove any fractions.

ToDaysDate =(Int(Iconv('01:20:00',"MTS")) + ((Date() +1)*86400 )) - (Int(Time()) + (Date()*86400 ))

Posted: Tue Jan 30, 2007 10:45 am
by DSguru2B
Agreed :wink: .