Back
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'
By using the below code, you can add -1 year to the current date:
SELECT ... From ... WHERE date > DATEADD(year,-1,GETDATE())
Try this query,
SELECT * FROM Tablename WHERE date >= DATEADD(YEAR, -1, GETDATE());
31k questions
32.8k answers
501 comments
693 users