Posted By

nilambar on 09/26/10


Tagged

php


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

seloh77


Calculate Age in PHP; given date of birth


 / Published in: PHP
 

Calculate age; given date.

  1. /*
  2. * calculateAge()
  3. * @action: calculate age from given date
  4. * @params:
  5. * birthday: birthday in format YYYY-MM-DD
  6. * @return: age (integer )
  7. * @modified : 27 August 2010
  8. * @modified by: Sucl Tandukar
  9. */
  10. function calculateAge ($birthday)
  11. {
  12. list($year,$month,$day) = explode("-",$birthday);
  13. $year_diff = date("Y") - $year;
  14. $month_diff = date("m") - $month;
  15. $day_diff = date("d") - $day;
  16. if ($day_diff < 0 || $month_diff < 0)
  17. $year_diff--;
  18. return $year_diff;
  19. }

Report this snippet  

You need to login to post a comment.