so i found a function for age some time ago and seems like it works SOME of the time, but ive recently run across some errors;
function age($patientsbirthday){
list($day,$month,$year) = explode("/",$patientsbirthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 && $month_diff==0){$year_diff--;}
if ($day_diff < 0 && $month_diff < 0){$year_diff--;}
return $year_diff;
}
The persons birthday is input as day, month (DEcember), and year (all varchar)
i convert the month to a number using
$monthnum = $row['birthmonth'];
$monthnum = date_parse($monthnum);
and then pass this to the function
$patientsbirthday = $row['birthday']. "/" . $monthnum['month'] ."/".$row['birthyear'];
heres a couple examples i get returned:
echo $patientsbirthday;
echo " (" . age($patientsbirthday) . ")";
10/4/2004 (10) correct
12/12/1991 (23) correct
1/12/2000 (15) incorrect
23/9/1969 (45) correct
3/9/1988 (27) incorrect
Anybody see something obvious i am doing wrong here?