note 49603 modified in function.gmmktime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:19:38 +0000 |
| Subject: | note 49603 modified in function.gmmktime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142051@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
<?php
$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;
?>
--was--
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;
http://php.net/manual/en/function.gmmktime.php