Mysql asks age from dob

My MySQL database has a date of birth stored in yyyy-mm-dd format, how can I query a database - without using php code - to show me the results of people born over x years and / or who are years old?

The table is called users, colum is called dob. I spent some time looking at the MySQL manual, but I cannot figure out exactly how to form my query.

So far I have gone on select * from users where dob..., but I don’t think that way.

+3
source share
1 answer

Use the command INTERVAL.

SELECT * from users where dob >= (CURDATE() - INTERVAL 18 YEAR)

This returns all users under the age of 18.

+2
source

Source: https://habr.com/ru/post/1738720/


All Articles