如何用身份证号码计算年龄|php根据身份证号码计算年龄

更新时间:2019-03-12    来源:生日祝福    手机版     字体:

【www.bbyears.com--生日祝福】

 代码如下
function getAgeByID($id){
       
//过了这年的生日才算多了1周岁
        if(empty($id)) return "";
        $date=strtotime(substr($id,6,8));
//获得出生年月日的时间戳
        $today=strtotime("today");
//获得今日的时间戳
        $diff=floor(($today-$date)/86400/365);
//得到两个日期相差的大体年数
       
//strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
        $age=strtotime(substr($id,6,8)." +".$diff."years")>$today?($diff+1):$diff;
 
        return $age;
    }
?>

本文来源:http://www.bbyears.com/zhufuduanxin/48640.html

猜你感兴趣

热门标签

更多>>

本类排行