PHP计算年龄
31,
2 => 28,
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31
);
$y = $m = $d = 0;
//天相减为正
if ($time['mday'] >= $birthday['mday']) {
//月相减为正
if ($time['mon'] >= $birthday['mon']) {
$y = $time['year'] - $birthday['year'];
$m = $time['mon'] - $birthday['mon'];
} else {
//月相减为负,借年
$y = $time['year'] - $birthday['year'] - 1;
$m = $time['mon'] - $birthday['mon'] + 12;
}
$d = $time['mday'] - $birthday['mday'];
return ($y == 0 ? '' : $y . '岁') . ($m == 0 ? '' : $m . '个月') . ($d == 0 || $y > 0 ? '' : $d . '天');
}
//天相减为负,借月
if ($time['mon'] == 1) { //1月,借年
$y = $time['year'] - $birthday['year'] - 1;
$m = $time['mon'] - $birthday['mon'] + 12;
$d = $time['mday'] - $birthday['mday'] + $monthDays[12];
return ($y == 0 ? '' : $y . '岁') . ($m == 0 ? '' : $m . '个月') . ($d == 0 || $y > 0 ? '' : $d . '天');
}
//3月,判断闰年取得2月天数
if ($time['mon'] == 3) {
$d = $time['mday'] - $birthday['mday'] + ($time['year'] % 4 == 0 ? 29 : 28);
} else {
$d = $time['mday'] - $birthday['mday'] + $monthDays[$time['mon'] - 1];
}
//借月后,月相减为正
if ($time['mon'] >= $birthday['mon'] + 1) {
$y = $time['year'] - $birthday['year'];
$m = $time['mon'] - $birthday['mon'] - 1;
} else {
//借月后,月相减为负,借年
$y = $time['year'] - $birthday['year'] - 1;
$m = $time['mon'] - $birthday['mon'] + 12 - 1;
}
return ($y == 0 ? '' : $y . '岁') . ($m == 0 ? '' : $m . '个月') . ($d == 0 || $y > 0 ? '' : $d . '天');
}
var_dump(datediffage($birthday, $time));
PHP计算年龄的更多相关文章
- iOS 获取当前时间以及计算年龄(时间差)
获取当前时间 NSDate *now = [NSDate date]; NSLog(@"now date is: %@", now); NSCalendar *calendar = ...
- Java 计算年龄
public static String getAgeTxt(String birthTime,String beginTime,int level){ if(StringUtils.isBlank( ...
- Excel中最精确的计算年龄的公式
身份证算年龄 假设A1是身份证号所在单元格 =IF(MONTH(NOW())<INT(MID(A1,11,2)),INT(YEAR(NOW())-INT(MID(A1,7,4)))-1,IF(M ...
- sql 身份证计算年龄和性别
IdentityNumber 是身份证号 年龄: ,), GETDATE()) / 365.25) as '推荐人年龄', 15位的身份证计算年龄: case when b.IdentityNumbe ...
- Java 根据出生日期计算年龄
1.把出生日期字符串转换为日期格式. public static Date parse(String strDate) throws ParseException { SimpleDateFormat ...
- 在Excel中根据某一个单元格的出生日期自动精确计算年龄
=IF(MONTH(NOW())<MONTH(G4),INT(YEAR(NOW())-YEAR(G4))-1,IF(MONTH(NOW())>MONTH(G4),YEAR(NOW())-Y ...
- SQL 根据日期精确计算年龄
SQL 根据日期精确计算年龄 第一种: 一张人员信息表里有一人生日(Birthday)列,跟据这个列,算出该人员的年龄 datediff(year,birthday,getdate()) 例:birt ...
- [JavaScript]YYYY-MM-DD格式字符串计算年龄
function getAge(birth){ birth = birth.replace(/-/g,"/"); //把格式中的"-"替换为"/&qu ...
- 依据出生日期Date 计算年龄
依据出生日期计算年龄 public class DateGetAge { public static int getAge(Date birthDay) throws Exception { Cale ...
- 问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题
SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,birthday)/12,1) FROM ltteacherinfo where name='朱雪东111'这个报错ORA 00 ...
随机推荐
- GIT里的一些名词
origin:他是一个特定远程仓库的别名,他不是一个仓库的属性. head:通常情况下可以将它与当前的分支等同.
- Effective Java 第三版——89. 对于实例控制,枚举类型优于READRESOLVE
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 生成建表脚本up_CreateTable
已经很久没用使用这个脚本了,今天用到,并做修改,增加了生成扩展属性功能. Go if object_ID('[up_CreateTable]') is not null Drop Procedure ...
- jQuery - Detect value change on hidden input field
You can simply use the below function, You can also change the type element. $("input[type=hidd ...
- /linux-command-line-bash-shortcut-keys/
https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-s ...
- C#通过用户名与密码访问共享目录
C#通过用户名与密码访问共享目录 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...
- E-WORK 对接 MTS 系统
E-WORK 目前的 E-WORK 系统主要包含了如下功能: 技能类型的管理 比如说品质检验技能.测试技能(成品测试或半成品测试).组装装配技能(打螺丝.合壳.点胶等).包装技能(封箱. ...
- windows上RSA密钥生成和使用
一,下载安装windows平台openssl密钥生成工具,执行安装目录bin下的"openssl.exe",执行后弹出命令窗口如下 运行 二,生成私钥 输入"genrsa ...
- Qt OpenGL 鼠标拾取实现
在之前的文章中讲到了OpenGL鼠标拾取操作的例子,工作中需要在Qt中实现,下面的程序演示了QT中opengl的拾取例子. 本例子在Qt5.12和Qt Creator4.8.0上测试,使用的是QOpe ...
- Qt编写自定义控件属性设计器
以前做.NET开发中,.NET直接就集成了属性设计器,VS不愧是宇宙第一IDE,你能够想到的都给你封装好了,用起来不要太爽!因为项目需要自从全面转Qt开发已经6年有余,在工业控制领域,有一些应用场景需 ...