根据生日计算年龄

/**
 * @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;
}
原文地址:https://www.cnblogs.com/jxl1996/p/10138980.html