note 43184 added to function.mktime
| From: | post at matthias-wuttke dot de | Date: | Sat, 12 Jun 2004 12:29:22 +0000 |
| Subject: | note 43184 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70963@lists.php.net to get a copy of this message | ||
Yet another birthday calculator. I think these two functions also work before 1970. Date format for
the birthdate is "YYYY-MM-DD".
<?php
// returns the age of a person
function age($birthdate) {
$date = explode("-", $birthdate);
$now = getdate();
$age = $now['year'] - $date[0];
if (time() < mktime(0, 0, 0, $date[1], $date[2], $now['year']))
$age--;
return $age;
}
// returns the next birthday
function next_birthday($birthdate) {
$date = explode("-", $birthdate);
$now = getdate();
$year = $now['year'] + 1;
if (time() < mktime(0, 0, 0, $date[1], $date[2], $now['year']))
$year--;
return $year . "-" . $date[1] . "-" . $date[2];
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43184
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43184&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43184&report=yes
Search -- http://master.php.net/manage/user-notes.php