php根据出生日期获取年龄


/**
 * @param $birthday 出生年月日(1992-1-3)
 * @return string 年龄
 */
function countage($birthday){
    $year=date('Y');
    $month=date('m');
    if(substr($month,0,1)==0){
        $month=substr($month,1);
    }
    $day=date('d');
    if(substr($day,0,1)==0){
        $day=substr($day,1);
    }
    $arr=explode('-',$birthday);

    $age=$year-$arr[0];
    if($month<$arr[1]){
        $age=$age-1;

    }elseif($month==$arr[1]&&$day<$arr[2]){
        $age=$age-1;

    }

    return $age;

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM