Age in Years for Given Birthdate


/ Published in: MySQL
Save to your folder(s)

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)


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.