本篇文章给大家介绍一下使用php实现根据出生年月日计算年龄的功能,结合实例形式分析了php日期相关转换与计算操作技巧。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
废话不多说,之间上代码:
nth = date('m',time()); $current_day = date('d',time()); if($birth_year >= $current_year){ return 0; } $age = $current_year - $birth_year - 1; if($current_month>$birth_month){ return $age+1; }else if($current_month == $birth_month && $current_day>=$birth_day){ return $age+1; }else{ return $age; } } //测试: echo getAgeByBirth('1988','4','8'); ?>
运行结果:
32
更多相关知识,请关注 考高分网!!
以上就是PHP实现根据出生年月日计算年龄的功能(代码示例)的详细内容,更多请关注考高分网其它相关文章!