Page 1 of 1

Subtract Hours from Current Timestamp

Posted: Tue Apr 26, 2016 4:07 pm
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.

Posted: Tue Apr 26, 2016 4:22 pm
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?

Posted: Tue Apr 26, 2016 4:25 pm
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.

Posted: Tue Apr 26, 2016 4:55 pm
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

Posted: Wed Apr 27, 2016 3:35 am
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.

Posted: Wed Apr 27, 2016 10:59 am
by cyclogenisis
Hi Craig, what do you mean by underflow?

Posted: Wed Apr 27, 2016 11:01 am
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.

Posted: Wed Apr 27, 2016 12:27 pm
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.