Zend - The PHP Company




Calculators

Add Code


Age Calculation  

Type: code fragment
Added by: mattnorniron
Entered: 02/06/2003
Last modified: 31/10/2006
Rating: *** (5 votes)
Views: 8203
Calculate anyone's age without worrying about the Unix Epoch


<?

/* I wrote this snippet to combat the limitations of the mktime function due to the beginning of the Unix Epoch. */

function calculate_age($birth_day$birth_month$birth_year) { 

     
$datestamp date("d.m.Y"mktime());
     
$t_arr explode("." $datestamp);
     
     
$current_day $t_arr[0];
     
$current_month $t_arr[1];
     
$current_year $t_arr[2];
     
     
$year_dif $current_year $birth_year;
     
     if((
$birth_month $current_month) || ($birth_month == $current_month && $current_day $birth_day))
         
$age $year_dif 1;
     else
         
$age $year_dif;

     return 
$age;

}


Usage Example




Rate This Script





Search



This Category All Categories