您的位置:首页 > 编程语言 > PHP开发

php根据身份证号码计算年龄

2014-01-18 09:17 519 查看
代码如下 复制代码

<?php
function getAgeByID($id){

//过了这年的生日才算多了1周岁
if(empty($id)) return '';
$date=strtotime(substr($id,6,8));
//获得出生年月日的时间戳
$today=strtotime('today');
//获得今日的时间戳 111cn.net
$diff=floor(($today-$date)/86400/365);
//得到两个日期相差的大体年数

//strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
$age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;

return $age;
}
?>

拒绝不带连接转载:http://www.111cn.net/phper/php/57198.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: