note 32979 deleted from function.date by pollita
| From: | pollita@php.net | Date: | Thu, 12 Jun 2003 18:58:53 +0000 |
| Subject: | note 32979 deleted from function.date by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50247@lists.php.net to get a copy of this message | ||
Note Submitter: Robby Zinchak
----
Wrote a function to figure out age. Watch out though, it doesn't (AFAIK) compute leapyears.
function age( $birthyear, $birthmonth, $birthday)
{
// This function does not take into account leapyears - aie!
$todayyear = date("Y");
$todaymonth = date("m");
$todayday = date("d");
// First subtract days
$ageday = $todayday - $birthday;
$agemonth = $todaymonth - $birthmonth;
$ageyear = $todayyear - $birthyear;
// Of course, these values could come out negative, and that would
// be a bad thing. So we will use php's broken time features
// to normalize the date this
// We do this by adding our time to 1970. Of course, PHP's date
// is broken, so we'll add only the remainder of 50 years
$fifties = floor($ageyear/50);
$fiftymod = $ageyear % 50;
$agesince1970 = mktime(0,0,0,
$agemonth,
$ageday,
$fiftymod+1970);
return $fifties * 50 + (date("Y", $agesince1970)-1970);
}