Display age based on birthday PHP script

I was looking for a way to keep the About section up to date and came across this one from Dzone that works really well:

function birthday ($birthday)
{
list($year,$month,$day) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
}

You can activate it with:

echo birthday("YYYY-MM-DD");

« - »

Comments

  1. Jimi | July 20th, 2010 | 2:35 am

    Thank you sir.

Post a comment