WPDKUser::age PHP Метод

age() публичный Метод

Return the age (in year) from a date in format YYYY-MM-DD or DD/MM/YYYY
public age ( string $birthday ) : integer
$birthday string Birth of date. MySQL YYYY-MM-DD o in formato data unico vincolo per adesso è il supporto solo per data italiana, ovvero giorno/meso/anno
Результат integer Age
    public function age($birthday)
    {
        $year_diff = 0;
        if (!empty($birthday)) {
            if (false !== strpos($birthday, '-')) {
                list($year, $month, $day) = explode('-', $birthday);
            } else {
                list($day, $month, $year) = explode('/', $birthday);
            }
            $year_diff = date('Y') - $year;
            $month_diff = date('m') - $month;
            $day_diff = date('d') - $day;
            if ($month_diff < 0 || $month_diff == 0 && $day_diff < 0) {
                $year_diff--;
            }
        }
        return intval($year_diff);
    }