Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nilaavu
Starting Member
18 Posts |
Posted - 2007-01-19 : 12:17:33
|
| How can I subtract a year from getdate() to get the Previos year date ? Thanx |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-19 : 12:33:40
|
| SELECT DATEADD(year, -1, GETDATE())But beware of leap year! If today is february 29, the query above will get either february 28, or march 1 previous year.Peter LarssonHelsingborg, Sweden |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-01-19 : 15:23:28
|
quote: Originally posted by Peso SELECT DATEADD(year, -1, GETDATE())But beware of leap year! If today is february 29, the query above will get either february 28, or march 1 previous year.Peter LarssonHelsingborg, Sweden
It will return Feb 28 if today is Feb 29. It works the same if you subtract one month from Dec 31; it returns Nov 30.CODO ERGO SUM |
 |
|
|
|
|
|