F
F
F(x)2018-11-22 12:45:49
SQL Server
F(x), 2018-11-22 12:45:49

How to get data from database up to 5 years old on SqlServer?

How can I get data from a database up to 5 years old on SqlServer? Tried like this:

DATEDIFF(YEAR, BirthDay, GETDATE()) <= 5
   --(GETDATE() - BirthDay_BirthDay) <= 5
  --BirthDay > DATEADD(YEAR,-5,GETDATE())
  --(YEAR(GETDATE())-YEAR(BirthDay)<=5)

but it doesn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
ponaehal, 2018-11-22
@ponaehal

and so?
DATEDIFF("yyyy", BirthDay, GETDATE()) <= 5
It would also be nice to make sure that BirthDay and GETDATE() are of the exact data type that you want to pass to the DATEDIFF input.
proof

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question