Aside from the fact you should use the built in functions for date diff, lets address the issue of why your presented code doesn't work as you expect by breaking it down.
function Agecalc($birthday)
{
list($day,$month,$year) = explode("/",$birthday);
$day_diff = date("d") - $day; // 9 - 19 = -10
$month_diff = date("m") - $month; // 3 - 2 = 1
$year_diff = date("Y") - $year; // 2012 - 1994 = 18
Now what you're doing in your original code is saying if the day diff or the month diff is negative, then the age is out by a whole year. This is fundamentally flawed, since when the day diff is negative the calculation is potentially out by only a month, not a year.
So you cater for the negative days by decrementing the month difference.
if ($day_diff < 0) {
$month_diff--;
}
Now the day diff is taken care of and our month diff = 0
. If it was negative we'd still need to account for it, so leave this block at the end.
if ($month_diff < 0) {
$year_diff--;
}
return $year_diff;
}
The final result from your example now returns 18
, because even after accounting for the negative days, the months are still positive.