Posted By

pitje on 09/02/07


Tagged

AGE


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hudge
Nix
philik


calculate age


 / Published in: PHP
 

Calculate current age in years from a given birthdate.

  1. function age ( $a_certain_date ) //returns years since $a_certain_date (format: YYYY/MM/DD)
  2. {
  3. list ( $year, $month, $day ) = explode ( "/", $a_certain_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.