As I wrote, the code works as long as $dobdt's year are 1902 or later, ie. a max age of 99 can be shown, it's tested.
The only other way I see a solution is that you -always- have the timeformat like 15/3/2001, ie. dd/mm/yyyy, and then split the date by /, and calculate on that, like this:
<?php
$dobdt = "16/3/1900"; // The date of birth
$admdt = "15/3/2001"; // The current date, or any date after the date of birth
$dobdt = explode("/",$dobdt); // Splitting the date of birth var
$dobdt["y"] = $dobdt[2]; // Putting the year part into a more desciptive arrayname
$dobdt["m"] = $dobdt[1]; // Putting the month part into a more desciptive arrayname
$dobdt["d"] = $dobdt[0]; // Putting the day part into a more desciptive arrayname
$admdt = explode("/",$admdt); // Splitting the current date var
$admdt["y"] = $admdt[2]; // Putting the year part into a more desciptive arrayname
$admdt["m"] = $admdt[1]; // Putting the month part into a more desciptive arrayname
$admdt["d"] = $admdt[0]; // Putting the day part into a more desciptive arrayname
$year = $admdt["y"]-$dobdt["y"]; // Calculating number of years between dates
if ($admdt["m"] == $dobdt["m"]) { // If months are the same, calculate the day
$day = $admdt["d"]-$dobdt["d"]; // Calculating days
if ($day < 0) { // If $day is negative, the birthday has yet to pass, ie. the still one year younger
$year = $year-1; // re-calculating the year
}
}
else { // If month are not the same, calculate the months
$month = $admdt["m"]-$dobdt["m"]; // Calculating months
if ($month < 0) { // If $month is negative, the birthday has yet to pass, ie. the still one year younger
$year = $year-1; // re-calculating the year
}
}
if ($year < 0) { // If $year is negative, you are born in the future, that is not possible
echo "You cannot be born in the future";
exit;
}
echo $year;
?>