Page 1 of 1

Add years to Date

Posted: Mon Dec 03, 2007 6:27 am
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

Posted: Mon Dec 03, 2007 7:34 am
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.

Posted: Mon Dec 03, 2007 7:50 am
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.

Re: Add years to Date

Posted: Mon Dec 03, 2007 8:20 am
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

Posted: Mon Dec 03, 2007 8:24 am
by chulett
True. It really boils down to exactly what you mean by a 'year'.

Posted: Mon Dec 03, 2007 2:20 pm
by ray.wurlod
Don't forget February 29th.

There is a set of date arithmetic functions downloadable from here which includes AddYearsToTimestamp() function.