Calculate Age in Years

Calculate anyone's age without worrying about the Unix Epoch

Resources

Server Side Code

http://www.zend.com/code/codex.php?id=1206&single=1
Type: code fragment
Added by: mattnorniron
Entered: 02/06/2003
Last modified: 06/12/2002

<?
 
/* 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;
 
}

Description, change title as needed

 

Client Side Code

Client side code is inherently insecure and error prone. It should be used to reduce load on server, and input verified by server. Please include server verification code also in this section.

Description, change title as needed

 

Candidate Code Suggestions

Add your suggestions and links here.