Current Date minus one year
-
Wednesday, February 11, 2009 1:43 AMHow 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 AMModerator
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- Proposed As Answer by gveeEditor Wednesday, February 11, 2009 8:50 AM
- Marked As Answer by Jinchun ChenMicrosoft Employee, Moderator Friday, March 06, 2009 9:07 AM
-
Wednesday, February 11, 2009 6:52 AM
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- Proposed As Answer by Nikka Lovely Wednesday, February 11, 2009 11:01 AM
- Marked As Answer by Jinchun ChenMicrosoft Employee, Moderator Friday, March 06, 2009 9:07 AM
-
Monday, March 15, 2010 8:30 PMYou can't do this as if fall under leap year (February 29, 2008)?
How you handle this?
-
Monday, March 15, 2010 8:34 PMModerator
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)

