note 49603 added to function.gmmktime
| From: | welchatadvomaticdotcom at osu1 dot php dot net | Date: | Wed, 02 Feb 2005 20:48:56 +0000 |
| Subject: | note 49603 added to function.gmmktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84387@lists.php.net to get a copy of this message | ||
Here is a handy routine for counting down to the minute, hour, and day to a timestamp
$minutesleft = floor(($timestamp - gmtime()) / 60);
if ($minutesleft < 0) {
$timeleft = 'NOW';
}
else if ($minutesleft < 60) {
$timeleft = ($minutesleft==1 ? '1 minute' : $minutesleft.' minutes');
}
else if ($minutesleft >= 60 && $minutesleft < (24*60)) {
$timeleft = (floor($minutesleft/60) == 1 ? '1 hour' :
floor($minutesleft/60).' hours');
}
else if ($minutesleft >= (24*60)) {
$days = floor($minutesleft / (24*60));
// hours remainder
$hours = ($minutesleft % (24*60)) / 60;
// hours left in the day
$hours_left = ((time() / 60) % (24*60)) / 60;
// see if the remainder of hours is greater than the hours left in today, if so increase the
days by one so that the days remaining mimics the date rather than how many 24 hour periods there
are between now and then.
if($hours > $hours_left) {
$days++;
}
$timeleft = ($days == 1 ? '1 day' : $days.' days');
}
echo $timeleft;
----
Manual Page -- http://www.php.net/manual/en/function.gmmktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49603
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49603&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49603&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49603&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49603&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49603&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49603&report=yes
Search -- http://master.php.net/manage/user-notes.php