Posted By

cahyadsn on 07/25/12


Tagged

mysql year AGE birthdate


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

philik


Age in Years for Given Birthdate


 / 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)

  1. #1
  2.  
  3. DATE_FORMAT( FROM_DAYS( TO_DAYS(CURDATE()) - TO_DAYS(@dob) ), '%Y' ) + 0
  4. YEAR(CURDATE()) - YEAR(@dob) - ( RIGHT(CURDATE(),5) < RIGHT(@dob,5) )
  5.  
  6. #2
  7. ROUND((((YEAR(NOW()) - YEAR(@dob)))*12 + (((MONTH(NOW()) - MONTH(@dob)))))/12, 2)

Report this snippet  

You need to login to post a comment.