失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php计算根据出生日期计算年龄

php计算根据出生日期计算年龄

时间:2020-04-18 10:17:44

相关推荐

php计算根据出生日期计算年龄

//根据出生日期计算年龄,如果传入的出生日期为.01格式,则把.正则替换为-function countAge($birthday){$birthday=preg_replace("/\./i", '-', $birthday);$age = strtotime($birthday);if($age === false){return false;}list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));$now = strtotime("now");list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));$age = $y2 - $y1;if((int)($m2.$d2) < (int)($m1.$d1))$age -= 1;return $age;}

如果觉得《php计算根据出生日期计算年龄》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。