I've already tried all other questions/solutions, and no answer. so here it is: I need to SELECT * FROM people WHERE
(dob is 18 to 40)
but my dob is stored as DATE
type YYYY-MM-DD
need to select people between 18 and 40 for example!
You need to use BETWEEN
with some year calculation TIMESTAMPDIFF(YEAR,'1980-02-04',NOW())
SELECT * FROM people WHERE TIMESTAMPDIFF(YEAR,`dob`,NOW()) BETWEEN 18 AND 40
See fiddle here
TIMESTAMPDIFF
YEAR(date)
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