Calculate Age of somebody in PHP

0
837

If you wish a function to calculate age of a person/car or whatever you want you have come to the right place. The following function will calculate age from a specific date. The date must be in a accepted format for the function strtotime.

function ageold($date){
    $time = strtotime($date);
    if($time === false){
      return '';
    }
 
    $year_diff = '';
    $date = date('Y-m-d', $time);
    list($year,$month,$day) = explode('-',$date);
    $year_diff = date('Y') - $year;
    $month_diff = date('m') - $month;
    $day_diff = date('d') - $day;
    if ($day_diff < 0 || $month_diff < 0) $year_diff-;
 
    return $year_diff;
}8

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here