How to add one year to a given date
Moderators: chulett, rschirm, roy
How to add one year to a given date
Pls. tell me any function is there to add one year to a given date
Thanks in advance
Vijay
Thanks in advance
Vijay
Vijay
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.
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
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Um... Hello? McFly! What's wrong with the help you've gotten so far?
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.
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
"You can never have too many knives" -- Logan Nine Fingers
-
- 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
Yes there is.vijaydev wrote:Pls. tell me any function is there to add one year to a given date
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You haven't even looked at the routines I suggested, have you?
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.