-
Calculate Age
I am trying to write a function that calculates the age of an individual exactly...not worried about month or days just years...every php function I have tried to use only calculates back to 1970...therefore anyone born before 1970 would show an age of 32. I need this function to be able to calculate the age of someone born back in the early 1880's and later...I have thought of just a basic calculation like this:
PHP Code:
function calculate_age($year)
{
$today = getdate();
$tyear = $today['year'];
$age = $tyear - $year;
return $age;
}
but it will still be inaccuarate....any ideas???
-
I figured it out....here is the function if anyone is interested.
It will calculate the age for someone born in the year 1 A.D. to now.
PHP Code:
function calculate_age($m, $d, $y)
{
$now = getdate();
$nmonth = $now['month'];
$nday = $now['mday'];
$nyear = $now['year'];
if ($nmonth < $m OR $nmonth = $m AND $nday < $d) {
$age = $nyear - $y - 1;
} else {
$age = $nyear - $y;
}
return $age;
}