版权声明:哈哈哈 https://blog.csdn.net/qq_39454048/article/details/84304593
function calcAge($birthday,$now) { if(!empty($birthday)){ if(!empty($now)) { $now = strtotime($now); }else{ $now = time(); } $age = strtotime($birthday); if($age === false){ return 0; } list($y1,$m1,$d1) = explode("-",date("Y-m-d", $age)); list($y2,$m2,$d2) = explode("-",date("Y-m-d"), $now); $age = $y2 - $y1; if((int)($m2.$d2) < (int)($m1.$d1)){ $age -= 1; } return $age; } return false; }