how SELECT people within age range

mysql, pdo, select

Solution

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)

Problem

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!

Original source

Related problems