Calculate Age By PHP

We can calculate age by the following code
<?php
if (!function_exists('calculate_age')) {
function calculate_age($startdate = '0000-00-00', $enddate = '0000-00-00') {
// Check to see if start date is valid
@list($year, $month, $day) = explode('-', $startdate);
if (@!checkdate($month,$day,$year)) {
return false;
}
// Create a new datetime object to do our calculations with
$s = new DateTime($startdate);
// We have to have an end date so if it is empty or 0000-00-00 we will make it right now
if (empty($enddate) OR $enddate == '0000-00-00') {
$enddate = 'now';
} else {
// Check to see if end date is valid
@list($year, $month, $day) = explode('-', $enddate);
if (@!checkdate($month,$day,$year)) {
return false;
}
}
// Create a new datetime object to compare as an end date
$e = new DateTime($enddate);
if ($s->format('Ymd') > $e->format('Ymd')) {
// End date cannot be before start date
return false;
}
// Calculate our base numbers here
$years = $e->format('Y')-$s->format('Y');
$months = $e->format('m')-$s->format('m');
$days = $e->format('d')-$s->format('d');
// We cannot have negative days
// Calculate how many days are in the startdate month
// subtract the startdate day and add 1
// Then add back in the day of the enddate
// Subtract 1 month
if ($days < 0) {
$days = $s->format('t')-$s->format('d')+1;
$days += $e->format('d');
$months--;
}
// We cannot have negative months
// Subtract 1 year and add back 12 months to make months positive
if ($months < 0) {
$years--;
$months += 12;
}
return array('years'=>$years,'months'=>$months, 'days'=>$days);
}
}
?>