July 25, 2011 at 2:26 am
Dear All,
Kindly i need to add one year except one week to the user registration date
how can i do that
Many thanks
July 25, 2011 at 2:37 am
July 26, 2011 at 2:57 pm
There are many ways you can do this depending on your criteria. If you are assuming a 52 week year the statement above will work.
But it does not handle Leap years the same.
select dateadd(wk,51,'2/29/2008') -- returns 2009-02-20 00:00:00.000
If you are looking at a specific date of registration to add a year then subtract 7 days the following statement would work. This would handle if the registration date was on a leap year.
select dateadd(dd, -7, dateadd(yyyy, 1, '2/29/2008')) -- returns 2009-02-21 00:00:00.000
Remember the code you use needs to be defined by your business rules on the registration date.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply