首页  >  文章  >  后端开发  >  PHP根据生日计算年龄(周岁)

PHP根据生日计算年龄(周岁)

PHP中文网
PHP中文网原创
2017-03-22 16:53:384801浏览

PHP根据生日计算年龄(周岁)

<?php/**
 * 根据时间戳计算年龄
 * @param $birth
 * @return mixed
 */functionhowOld($birth) {list($birthYear, $birthMonth, $birthDay) = explode(&#39;-&#39;, date(&#39;Y-m-d&#39;, $birth));
    list($currentYear, $currentMonth, $currentDay) = explode(&#39;-&#39;, date(&#39;Y-m-d&#39;));
    $age = $currentYear - $birthYear - 1;
    if($currentMonth > $birthMonth || $currentMonth == $birthMonth && $currentDay >= $birthDay)
        $age++;

    return$age;
}
?>

以上就介绍了PHP根据生日计算年龄(周岁),包括了方面的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关文章:

php根据生日计算年龄的方法

php根据生日计算年龄/生肖/星座实例

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn