How to get last hour from System time at Sequence?

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
kennyyeung.kw
Participant
Posts: 5
Joined: Tue Sep 08, 2009 8:45 pm

How to get last hour from System time at Sequence?

Post by kennyyeung.kw »

I define a User Variables Activity and wanted to make 4 parameter base on the system datetime - 1 hour
year int
month int
day int
hour int
Is there any function i can use ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not one function, but you can build it up from more than one, including Date() or @DATE (date in internal format), Time() or @TIME (time in internal format) and doing the time arithmetic for the one hour offset. You could do all that in a server routine, too.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kennyyeung.kw
Participant
Posts: 5
Joined: Tue Sep 08, 2009 8:45 pm

Post by kennyyeung.kw »

i dont know the function to perform the dateadd ..
i can get the date by @DATE
but i find no solution to get the date of (@Date - 1 hour )
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You need to get the time as well, that or TimeDate() which gets both. And 1 hour = 3600 seconds, which is what you would need to subtract from the internal time, then convert back.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kennyyeung.kw
Participant
Posts: 5
Joined: Tue Sep 08, 2009 8:45 pm

Post by kennyyeung.kw »

I know little about Datastage basic and
I can't find any function for dateadd
i have tried
Iconv(TimeDate(),"D") -3600
or
TimeDate() -3600
result is not correct
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

However Time() - 3600 is correct. If that result is negative you have to subtract 1 from the date.

Code: Select all

If @TIME < 3600 Then Oconv(@DATE - 1, "D-YMD[4,2,2]") : " " : Oconv(@TIME + 86400 - 3600, "MTS") ElseOconv(@DATE, "D-YMD{4,2,2]") : " " : Oconv(@TIME - 3600, "MTS")
Last edited by ray.wurlod on Tue Feb 15, 2011 4:03 am, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kennyyeung.kw
Participant
Posts: 5
Joined: Tue Sep 08, 2009 8:45 pm

Post by kennyyeung.kw »

Problem Solved .. Thanks for help =]
Post Reply