Re: Re: strtotime

From: Date: Sun, 17 Oct 2010 19:34:31 +0000
Subject: Re: Re: strtotime
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-308768@lists.php.net to get a copy of this message
Yaay, I'm 45 now :). Here is another nifty piece of code I found. How does this work? What is 31556926? function calculateAge($birthday){
    return floor((time() - strtotime($birthday))/31556926);
} echo calculateAge('1965-10-17'); http://ca.php.net/manual/en/function.floor.php -------------------------- $birthday = '1965-08-30'; //calculate years of age (input string: YYYY-MM-DD) function birthday ($birthday){
    list($year,$month,$day) = explode("-",$birthday);
    $year_diff  = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff   = date("d") - $day;
# if ($day_diff < 0 || $month_diff < 0)
    if (($month_diff == 0 && $day_diff < 0) || $month_diff < 0)
      $year_diff--;
    return $year_diff;
} echo birthday ($birthday);

« previous php.general (#308768) next »