How to Calculate Age with PHP

Found this cool snippet with returns how old is somebody from a given birthday.

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 ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; }

Please note there is a lot of variatons and I'm sure it could be done better.

8 comments

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*