Date subtraction into seconds

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
rayx0063
Participant
Posts: 3
Joined: Thu Feb 26, 2004 10:04 am

Date subtraction into seconds

Post 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.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You mean KBATimestampDeltaSecondsroutine.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rayx0063
Participant
Posts: 3
Joined: Thu Feb 26, 2004 10:04 am

Post 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 ))
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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 )
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rayx0063
Participant
Posts: 3
Joined: Thu Feb 26, 2004 10:04 am

Post 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 ))
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Agreed :wink: .
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply