/ Published in: MySQL
Given a birthdate in @dob, here are two simple formulae for age in years : (the second formulae is for age in years to two decimal places, ignoring day of month)
Expand |
Embed | Plain Text
#1 DATE_FORMAT( FROM_DAYS( TO_DAYS(CURDATE()) - TO_DAYS(@dob) ), '%Y' ) + 0 YEAR(CURDATE()) - YEAR(@dob) - ( RIGHT(CURDATE(),5) < RIGHT(@dob,5) ) #2 ROUND((((YEAR(NOW()) - YEAR(@dob)))*12 + (((MONTH(NOW()) - MONTH(@dob)))))/12, 2)
You need to login to post a comment.
