Add years to Date

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
bmnaidu
Charter Member
Charter Member
Posts: 16
Joined: Wed Jun 07, 2006 5:49 am

Add years to Date

Post by bmnaidu »

Hello,
I want to add 100 years for the TimeStamp. How to do it? Thought of adding days, but is there any other way to do this?

Thanks in advance.
Naidu Buddha
Thanks and Regards
NAIDU BUDDHA
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure, you can 'add days' as long as you don't care about leap years: 100 years in days is just + (100 * 365).

You'd have to get more sophiticated to handle this properly. From what I recall, Ken Bland has routines to do this on his website and may have posted them here as well. Ray Wurlod has Server date routines on his site as well. Both can be found via links in any of their posts, I do believe.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srinagesh
Participant
Posts: 125
Joined: Mon Jul 25, 2005 7:03 am

Post by srinagesh »

If your source is a database, you can use the database functions to generate this column.

Eg: In Oracle

select add_months(sysdate,12) from dual;

will add 12 months to current date.
NickH
Participant
Posts: 6
Joined: Mon Jul 26, 2004 7:46 am

Re: Add years to Date

Post by NickH »

bmnaidu wrote:Hello,
I want to add 100 years for the TimeStamp. How to do it? Thought of adding days, but is there any other way to do this?

Thanks in advance.
Naidu Buddha
Probably the most simplistic approach is

(DSJobStartTimestamp[1,4]+100):DSJobStartTimestamp[15]

replace DSJobStartTimestamp with whatever your timestamp is
2007-12-03 14:16:52 becomes 2107-12-03 14:16:52
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True. It really boils down to exactly what you mean by a 'year'.
-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 »

Don't forget February 29th.

There is a set of date arithmetic functions downloadable from here which includes AddYearsToTimestamp() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply