php 根据生日计算年龄
// 根据出生日期求年龄
function getAgeByBirthday($val = "") {
if($val == "") {
return 45;
}
$tYear = date('Y');
$tMonth = date('m');
$tDay = date('d');
$year = substr($val, 0, 4);
$month = substr($val, 5, 2);
$day = substr($val, 8, 2);
$age = intval($tYear) - intval($year);
if (intval($tMonth) < intval($month)) {
$age -= 1;
} else if(intval($tMonth) == intval($month) && intval($tDay) < intval($day)) {
$age -= 1;
}
return $age;
}
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »