Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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'

2 Answers

0 votes
by (40.9k points)

By using the below code, you can add -1 year to the current date:

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

0 votes
by (1.7k points)

Try this query,

SELECT * FROM Tablename WHERE date >= DATEADD(YEAR, -1, GETDATE());

Related questions

0 votes
3 answers
asked Dec 16, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 9, 2020 in SQL by Appu (6.1k points)

1.4k questions

32.9k answers

507 comments

693 users

...