php 根据日期 指定时间 生日计算年龄

if (!function_exists('get_age')){
    function get_age($birthday){
        $iage = 0;
        $year = date('Y',strtotime($birthday));
        $month = date('m',strtotime($birthday));
        $day = date('d',strtotime($birthday));
        $now_year = date('Y');
        $now_month = date('m');
        $now_day = date('d');
        if ($now_year > $year) {
            $iage = $now_year - $year - 1;
            if ($now_month > $month) {
                $iage++;
            } else if ($now_month == $month) {
                if ($now_day >= $day) {
                    $iage++;
                }
            }
        }
        return $iage;
    }
}

 

© 版权声明
THE END
喜欢就支持一下吧
分享