How to search age wise if DOB is stored in Database

Hai,

i am doing Age wise search i.e age between two age but i am storing DOB in database …
How can i do age wise …?

any suggestion please…

thanks,

As long as you’re storing dob as a DATE this should be as easy as calculating the age and using that.

ie

SELECT
  name,
  dob
FROM person
WHERE YEAR(CURRENT_TIMESTAMP) - YEAR(dob) BETWEEN ? AND ?

Except that the difference in years isn’t your age if your birthday hasn’t occurred yet in the year. You will be that age this year, but you might not be it yet. The following returns the number of whole years between two dates -

TIMESTAMPDIFF(YEAR, dob_column, CURDATE())
2 Likes

thank you,
but i am using multi select ages like in checkbox like
age=18,19,20

so how can i modify the above query
Capture11

any suggestion please…!

that looks more like an IN query than BETWEEN…

Sponsor our Newsletter | Privacy Policy | Terms of Service