PHP常用函数之根据生日计算年龄功能示例
网络编程 2021-07-04 23:05www.168986.cn编程入门
这篇文章主要介绍了PHP常用函数之根据生日计算年龄功能,结合实例形式分析了php日期相关转换与计算操作技巧,需要的朋友可以参考下
本文实例讲述了PHP常用函数之根据生日计算年龄功能。分享给大家供大家参考,具体如下:
/** * 根据出生年月日计算出年龄 * @param $birth_year * @param $birth_month * @param $birth_day * @return int */ function getAgeByBirth($birth_year,$birth_month,$birth_day){ if(empty($birth_year) || empty($birth_month) || empty($birth_day)){ return 0; } $current_year = date('Y',time()); $current_month = 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','8','8');
运行结果:
31
PS:这里再为大家推荐几款时间及日期相关工具供大家参考:
在线日期/天数计算器:
在线日期计算器/相差天数计算器:
在线日期天数差计算器:
Unix时间戳(timestamp)转换工具:
更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
上一篇:PHP常用函数之获取汉字首字母功能示例
下一篇:PHP常用函数之格式化时间操作示例
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程