SQL Server: Get data for only the past year

Josh Mein picture Josh Mein · Aug 27, 2008 · Viewed 292.4k times · Source

I am writing a query in which I have to get the data for only the last year. What is the best way to do this?

SELECT ... FROM ... WHERE date > '8/27/2007 12:00:00 AM'

Answer

samjudson picture samjudson · Aug 27, 2008

The following adds -1 years to the current date:

SELECT ... From ... WHERE date > DATEADD(year,-1,GETDATE())