- date: documentation ( source)
- strtotime: documentation ( source)
<?php
function getAge($dob) {
$dob = strtotime($dob);
$y = date('Y', $dob);
if (($m = (date('m') - date('m', $dob))) < 0) {
$y++;
} elseif ($m == 0 && date('d') - date('d', $dob) < 0) {
$y++;
}
return date('Y') - $y;
}
/*** a date before 1970 ***/
$dob = "April 20 1961";
/*** another date ***/
$tdate = "21-04-2009";
/*** show the date ***/
echo getAge( $dob, $tdate );