根据生日计算年龄
/** * @uses 根据生日计算年龄,生日的格式是:2016-09-23 * @param string $birthday * @return string|number */ function calcAge($birthday) { $iage = 0; if (!empty($birthday)) { $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; }
=======================================
由于本人水平有限,文章在表述和代码方面如有不妥之处,欢迎批评指正。留下你的脚印,欢迎评论哦。你也可以关注我,一起学习哦!