How to add one year to a given 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
vijaydev
Participant
Posts: 54
Joined: Sun May 20, 2007 6:31 pm

How to add one year to a given date

Post by vijaydev »

Pls. tell me any function is there to add one year to a given date

Thanks in advance


Vijay
Vijay
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No. You'd need to have a clear understanding what precisely 'adding a year' to any given date means and then write your own. You'd also need to know what kind of dates you need to handle - any format? One particular format? What format do you return the result in? Things to think about.

If it is as simple as incrementing the year portion of the date, then one way would be to substring it off, increment, and then concatenate it back together.
-craig

"You can never have too many knives" -- Logan Nine Fingers
vijaydev
Participant
Posts: 54
Joined: Sun May 20, 2007 6:31 pm

Post by vijaydev »

"YYYY-MM-DD" i need to add one year to this the out put format is same

Eg: 2007-06-09 i need to get 2008-06-08

2007-06-01 then i need 2007-05-31
Vijay
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So... you just want to add 365 days to the date? Is that what this boils down to? :?

Use IConv to convert the date to internal format, add 365 and then convert back to your external format with OConv.
-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 »

Adding one to the year portion always works unless the starting date is Feb 29, in which case you also need to subtract one from the day number.

Or you could download a function from here where you will find both AddYears (to date) and AddYearsToTimestamp functions among others. Each has its own documentation on the General page, including instructions as to how it is to be used, what format arguments are expected to be in, and so on.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah yes... the Patent Pending Ray Wurlod Date Routines. Excellent stuff. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
vijaydev
Participant
Posts: 54
Joined: Sun May 20, 2007 6:31 pm

Post by vijaydev »

Any one help in this regard
Vijay
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Um... Hello? McFly! What's wrong with the help you've gotten so far? :evil:

If we're way off the mark, say so. And if so, you could start off by explaining why you "need" to get 2008-06-08 when you add "1 year" to 2007-06-09. I think most people would assume the date should be 2008-06-09. Explain the rule you need to implement.
Last edited by chulett on Sun Jun 10, 2007 7:27 am, edited 1 time in total.
-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:

Re: How to add one year to a given date

Post by ray.wurlod »

vijaydev wrote:Pls. tell me any function is there to add one year to a given date
Yes there is.

I gave you a link whence you can download a whole suite of them.

If you want more help than that, such as designing your ETL, that counts as consulting, and will cost you.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vijaydev
Participant
Posts: 54
Joined: Sun May 20, 2007 6:31 pm

Post by vijaydev »

What about Leap year


Regards,
Vijay
Vijay
rafik2k
Participant
Posts: 182
Joined: Wed Nov 23, 2005 1:36 am
Location: Sydney

Post by rafik2k »

for leap year u need to check year first for leap year like following:

Code: Select all

if (mod(year,4)=0 or mod(year,100)=0 or mod(year,400)=0) then
  // for leap year
  add 366 days
else
  // not leap year
 add 365 days
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You haven't even looked at the routines I suggested, have you?
:roll:

Leap years actually do not matter in an AddYears() function unless the current (base) date is February 29th or the Pope has adjusted the calendar in the interim.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:or the Pope has adjusted the calendar in the interim.

Yah, gotta watch out for them Popes. They does stuffs like that every now and then. :wink:
-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 »

Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 - see this site for details.

My routine handles this situation, because the underlying "UniVerse" date handling functions are aware of it.

But it would appear vijaydev is not interested in a supplied, totally correct, solution.
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