Posted By

ginoplusio on 02/10/10


Tagged

date AGE birthday birthdate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ginoplusio
NyX


PHP how to calculate age from date of birth


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/02/10/php-how-to-calculate-age-from-date-of-birth/

  1. // input $date string format: YYYY-MM-DD
  2. function age($date){
  3. list($year,$month,$day) = explode("-",$date);
  4. $year_diff = date("Y") - $year;
  5. $month_diff = date("m") - $month;
  6. $day_diff = date("d") - $day;
  7. if ($day_diff < 0 || $month_diff < 0) $year_diff--;
  8. return $year_diff;
  9. }

Report this snippet  

You need to login to post a comment.