form calculate age from date php code example
Example 1: calculate person age by birthdate php
public function getAge($date)
{
$dob = new DateTime($date);
$now = new DateTime();
$difference = $now->diff($dob);
$age = $difference->y;
return $age;
}
Example 2: age php datetime
function get_age( $date ) {
$age = date('Y') - $date;
if (date('md') < date('md', strtotime($date))) {
return $age - 1;
}
return $age;
}