mysql querying age from dob
My MySQL database has date of 开发者_JS百科birth stored in the format yyyy-mm-dd, how do I query the database - without using php code - to show me results of people born within x years of now, and/or, who are y years of age?
The table is called users, the colum is called dob. I've spent a while viewing the MySQL manual but I can't work out precisely how to form my query.
So far I went for select * from users where dob...
but I don't think that's the way to go.
Use the INTERVAL
command.
SELECT * from users where dob >= (CURDATE() - INTERVAL 18 YEAR)
This returns all users under the age of 18.
精彩评论