Subtract Hours from Current Timestamp

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Subtract Hours from Current Timestamp

Post by cyclogenisis »

Hello,

I am looking to get the current timestamp minus 5 hours. For example if right now is:

2016-04-26 18:01:15
It will return 2016-04-26 13:01:15

Another example if now is:
2016-04-26 01:01:15
It will return: 2016-04-25 20:01:15

Looking to do this in a user variable stage.
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

chulett wrote:TimestampOffsetByComponents() ...
Thanks Craig. How would I get the full result in the desired format?

Also I mentioned I am trying to accomplish this in user variable stage. Does this function work in that stage?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You were too quick. I removed my post when I noticed you said "in a User Variable stage" (which means a Sequence job) and I thought you were looking for a Parallel function. While I was removing it you replied.

No it does not and we're in the wrong forum to boot. Hang on a sec.
-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 »

Perhaps Ray is still giving away his BASIC routines to do date and time math, that would certainly make things easier. Otherwise I think you're going to need do some of your own. Something like:

1. IConv to convert the time to internal format
2. Subtract 18000 (5 hours in seconds)
3. Handle any 'underflow' including subtracting 1 day from the date
4. OConv to put it all back into a string
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Click any of the links on my new home page which takes you to a public page on OneDrive. Download RayWurlodDateRoutines.dsx from there.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

Hi Craig, what do you mean by underflow?
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

Thanks Ray, I see AddDaytoTimestamp, nothing with hourly I'll try to see how I can edit one of these and get familiar with building routines, don't have much experience in this area. However, I'm looking for a solution as quick as possible with since my time is very limited.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Time in internal format is the number of seconds past midnight. When you subtract 18000 seconds from it, it may go negative which is what I meant by 'underflow'. When that happens, you need to decrement the day by 1 and then adjust the time accordingly... add back 86400 seconds... something I'm sure Ray is already doing and you can crib from if need be.

In other words, the scenario you covered in your second example.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply