note 67987 added to function.date
| From: | Aristia at osu1 dot php dot net | Date: | Sat, 08 Jul 2006 18:12:50 +0000 |
| Subject: | note 67987 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114599@lists.php.net to get a copy of this message | ||
I wrote a small function for calculating birthdays. The days count doesn't seem accurate but
the years and months are correct. It seems to be rough around the edges but it works for me :)
function elapsed($year, $month, $day) {
$bdaystamp = mktime(0,0,0, $month, $day, $year);
$today = date("U");
$elapsed = $today - $bdaystamp;
$years_remainder = $elapsed%31536000;
$rawyears = $elapsed-$years_remainder;
$years = $rawyears/31536000;
$months_remainder=$years_remainder%2628000;
$rawmonths = $years_remainder-$months_remainder;
$months = $rawmonths/2628000;
$days_remainder=$months_remainder%86400;
$rawdays = $months_remainder-$days_remainder;
$days = $rawdays/86400;
$yearword = "Years";
$monthword = "Months";
$daysword = "Days";
$age= $years.' '.$yearword.' '.$months.' '.$monthword.'
'.$days.' '.$daysword.'';
return $age;
}
$age=elapsed("1978", "01", "18");
----
Server IP: 85.116.0.130
Probable Submitter: 80.3.160.5 (proxied: 82.25.146.227)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/note/edit/67987
Del: integrated -- http://master.php.net/note/delete/67987/integrated
Del: useless -- http://master.php.net/note/delete/67987/useless
Del: bad code -- http://master.php.net/note/delete/67987/bad+code
Del: spam -- http://master.php.net/note/delete/67987/spam
Del: non-english -- http://master.php.net/note/delete/67987/non-english
Del: in docs -- http://master.php.net/note/delete/67987/in+docs
Del: other reasons-- http://master.php.net/note/delete/67987
Reject -- http://master.php.net/note/reject/67987
Search -- http://master.php.net/manage/user-notes.php