Date Time (Adding date problem)

  • Dear All,

    Kindly i need to add one year except one week to the user registration date

    how can i do that

    Many thanks

  • Do you want to add 51 weeks to the date ?

    Year has 52 therefore 51 is a whole year minus the last week.

    select dateadd(wk,51,GETDATE())

    Jayanth Kurup[/url]

  • 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