note 14434 deleted from function.mktime by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 13:11:52 +0000 |
| Subject: | note 14434 deleted from function.mktime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59884@lists.php.net to get a copy of this message | ||
Note Submitter: d.heldens@qsa.nl
----
This is simple code for calculating current age and day's till next birthday:
// first get the current date
$nowdate = mktime(0,0,0,date("m"),date("d"),date("Y"));
// this is my birthday
$birthday = mktime(0,0,0,"10","28","1980");
// calculate my age in years
$age=intval(($nowdate-$birthday)/(60*60*24*365));
echo "I'm now $age years old.";
// my next birthday
$nextbirthday = mktime(0,0,0,"10","28",date("Y"));
// if $nextbirtday is in the past, add 1 year to $nextbirthday
if ($nextbirthday<$nowdate) {
$nextbirthday=$nextbirthday+(60*60*24*365);
}
// calculate the remaining day's till my next birthday
$daycount=intval(($nextbirthday-$nowdate)/(60*60*24));
echo " My next birthday is over $daycount day's.";
Dennis Heldens.