note 44031 added to function.date
| From: | allenatekonmatdotcom at rn2 dot php dot net | Date: | Tue, 13 Jul 2004 07:55:19 +0000 |
| Subject: | note 44031 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73135@lists.php.net to get a copy of this message | ||
(Sorry about my poor english...)
Calculate someone's age with year, month and day.
If someone's birthday is 1975-11-19.
**********
<?php
$birthday = mktime(0, 0, 0, 11, 19, 1975);
$ageyear = date("Y", time()) - date("Y", $birthday);
$agemonth = date("m", time()) - date("m", $birthday);
$ageday = date("d", time()) - date("d", $birthday);
if ($ageday < 0) {
$agemonth = $agemonth -1;
$ageday = $ageday + 30;
}
if ($agemonth < 0) {
$ageyear = $ageyear - 1;
$agemonth = $agemonth + 12;
}
echo $ageyear . "year(s)" . $agemonth . "month(s)" . $ageday .
"day(s)";
?>
**********
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44031
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44031&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44031&report=yes
Search -- http://master.php.net/manage/user-notes.php