note 32979 added to function.date
| From: | Robby at rack1 dot php dot net | Date: | Thu, 12 Jun 2003 18:01:33 +0000 |
| Subject: | note 32979 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50246@lists.php.net to get a copy of this message | ||
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);
}
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32979
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32979&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32979&report=yes