I have an SQL table called member in which I have member information and in that information, their birth date.
I need to get a list of all the people that are more than 25 years old. For now, I got this :
SELECT * FROM members
WHERE DATEDIFF(year, birthday, GETDATE() ) > 25
The only thing is that it doesn't take into consideration all the people that turned 25 this year so far...
How do I add to this everyone that turned 25 in January and February of this year as well ?
Would someone be able to help me out ?
Thanks !
Don't use datediff(). Just subtract the years from the current date:
where birthday < dateadd(year, -25, getdate())
Try adding 25 years to their birthday and then comparing to now. If <=, then they are older than 25.
SELECT *
FROM members
WHERE DATEADD(year, 25, birthday) <= getdate()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With