A date calculator:
function getAge($date, $futureDate=false)
{
if(preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$/', $date) == false) {
return false;
}
elseif($futureDate!==false && preg_match('/^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$/', $futureDate) == false) {
return false;
}
list($m, $d, $y) = split('[/.-]', trim($date));
$start = mktime(0, 0, 0, $m, $d, $y);
$end = mktime(); // 1970s unix bday
if($futureDate!==false) {
list($m, $d, $y) = split('[/.-]', trim($futureDate)); // delimiter can be slash, dot, or hyphen
$end = mktime(0, 0, 0, $m, $d, $y);
}
$age = abs($end - $start);
$y = $age / (365 * 24 * 60 * 60);
$m = strstr($y, '.') * 12; // not month but number months
$h = $age / (365 * 24); // hours in period
return array(
'y' => floor($y),
'm' => floor($m),
'h' => floor($h),
's' => $age
);
}