note 9643 added to Date and Time functions
| From: | memm at gmx dot net | Date: | Thu, 16 Nov 2000 14:58:49 +0000 |
| Subject: | note 9643 added to Date and Time functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7782@lists.php.net to get a copy of this message | ||
need the age of a person or how many years passed since a certain date?
this should work, also works when the person is born on Feb, 29th
function get_age($birthday) {
if (!ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $birthday, $regs)) { return false;} //
Geb-Datum nicht korrekt übergeben
$age = date("Y") - $regs[1];
if ($regs[2] > date("m")) {$age--;}
elseif ($regs[2] == date("m")) {
if ($regs[3] > date("d")) {$age--;}
}
return $age;
} // Ende function get_age
http://www.php.net/manual/ref.datetime.php