1. 程式人生 > >PHP根據生日計算年齡(週歲)

PHP根據生日計算年齡(週歲)

<?php /** * 根據時間戳計算年齡 * @param $birth * @return mixed */ function howOld($birth) { list($birthYear, $birthMonth, $birthDay) = explode('-', date('Y-m-d', $birth)); list($currentYear, $currentMonth, $currentDay) = explode('-', date('Y-m-d')); $age = $currentYear - $birthYear - 1; if
($currentMonth > $birthMonth || $currentMonth == $birthMonth && $currentDay >= $birthDay) $age++; return $age; } ?>