php根据出生日期获取年龄

Posted lei12138

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

}
转载于:http://www.cnblogs.com/jcydd/p/7278401.html

以上是关于php根据出生日期获取年龄的主要内容,如果未能解决你的问题,请参考以下文章