Mike Sav
Mike Sav

Reputation: 15321

How do I select records less than 1 year old?

This should be a fairly simple question but I know very little about SQL. I have a database which has the following fields:

Now I wish to select all the records that are less than 1 year old from when the SQL statement is run. I know I should use DateDiff, anyone got any ideas?

Thanks

Upvotes: 31

Views: 65851

Answers (3)

user6119812
user6119812

Reputation:

select ... from ... where YEAR(GETDATE()) - YEAR(YOURDATE) = 1

Upvotes: 1

STEVE
STEVE

Reputation: 31

TRY

SELECT * FROM TABLE_NAME WHERE SYSTEM_DATE > DATEADD(YYYY, -1, GETDATE())

(UNTESTED)

Upvotes: 3

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

select *
from MyTable
where MyDate > DATEADD(year, -1, GetDate())

Upvotes: 73

Related Questions