Answered Current Date minus one year

  • Wednesday, February 11, 2009 1:43 AM
     
     
    How would I write a simple command to show the current date minus exactly one year?

    Any advice is appreciated.

    Thanks,
    Ryan

    Ryan Mcbee

All Replies

  • Wednesday, February 11, 2009 2:01 AM
    Moderator
     
     Answered

    Hi Ryan,

    GetDate() returns the current date, and DateAdd can be used for date math.  You would do this:

    SELECT DateAdd(yy, -1, GetDate())

    HTH!


    Aaron Alton | thehobt.blogspot.com
  • Wednesday, February 11, 2009 6:52 AM
     
     Answered
    Hello,

    You can also use either year or yy or yyyy like

    SELECT DATEADD(Year,-1,GETDATE())

    Link for more details
    http://msdn.microsoft.com/en-us/library/ms186819.aspx

    Hope helpful...


    Pavan http://www.ggktech.com
  • Monday, March 15, 2010 8:30 PM
     
     
    You can't do this as if fall under leap year (February 29, 2008)?
    How you handle this?
  • Monday, March 15, 2010 8:34 PM
    Moderator
     
     
    You can't do this as if fall under leap year (February 29, 2008)?
    How you handle this?

    It depends on what you WANT to happen?

    What should the Year-Ago date be based on Feb29,2008?

    Shouldn't it be Feb28,2007?

    Or do you think it should be Mar01,2007?

    --Brad (My Blog)