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 |
|
MyronCope
Starting Member
46 Posts |
Posted - 2007-03-15 : 10:13:15
|
| I need to subtract a year from a datetime field. I need this for a query to bring back all records created in a table in the last year.However, when I try this it only subtracts one from the day field. Does anyone know the right syntax for this? Thanks much.The code below:<CODE>SELECT * FROM SOME_TABLEWHERE Date_Created > (GetDate() - 1)</CODE> |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-15 : 10:16:39
|
[code]SELECT * FROM SOME_TABLEWHERE Date_Created > dateadd(year, -1, GetDate())[/code] KH |
 |
|
|
|
|
|