Hello, I was wondering if someone can tell me how to get age (in years) from Date field in the MySQL database. For example, I need to search the database for a member who is more than 18 and less than 20 years old. SELECT * FROM members WHERE date_converted_to_age>18 AND date_converted_to_age<20 So, what do I write instead of date_converted_to_age? Thank you in advance for all your help!
from http://ma.tt/2003/12/calculate-age-in-mysql/ Therefore, this should work with everyone who wasn’t born in the future. SELECT DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(dob, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(dob, '00-%m-%d')) AS age where dob is date of birth. Code (markup):