Anuar  Maratkhan Anuar Maratkhan - 2 months ago 7
SQL Question

presenting age more than [number] from birth date in sql

I have a table called dependent:

enter image description here

And now I need to present the dependents more than 40 years old for example.

P.S. Right now I am trying to use

DATEDIFF(CURDATE(), dependent.bdate)/365.25
function, but still can't present it. How to do this?

Answer

Assuming bdate is an actual DATE column, I think it would be easier to create a date 40 years prior to the current date and select where bdate is less-than or equal to that date

WHERE dependent.bdate <= DATE_SUB(CURDATE(), INTERVAL 40 YEAR)