Calculate Age of somebody in PHP

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;


Leave a Reply

Your email address will not be published. Required fields are marked *