note 47582 added to function.time
| From: | xaxisx at gmail dot com | Date: | Sun, 21 Nov 2004 23:37:12 +0000 |
| Subject: | note 47582 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80840@lists.php.net to get a copy of this message | ||
Here is a simple tool, that will convert a timestamp (created with mktime()) into a count down until
that event (in which the name of the event can also be specified)....
<?php
// converttime() - create a
// countdown to a future
// event/time.
function converttime($event, $thing)
{
$time = time();
$date = date("r", $event);
$eval = $event - $time;
$ydiv = $eval / 31536000;
$ymod = $eval % 31536000;
$year = floor($ydiv);
$ndiv = $ymod / 2592000;
$nmod = $ymod % 2592000;
$mont = floor($ndiv);
$wdiv = $nmod / 604800;
$wmod = $nmod % 604800;
$week = floor($wdiv);
$ddiv = $wmod / 86400;
$dmod = $wmod % 86400;
$days = floor($ddiv);
$hdiv = $dmod / 3600;
$hmod = $dmod % 3600;
$hour = floor($hdiv);
$mdiv = $hmod / 60;
$mmod = $hmod % 60;
$minu = floor($mdiv);
echo "$year years, $mont months, $week weeks, $days days, $hour hours, $minu minutes and
$mmod seconds\n";
echo "until $date, $thing";
}
$open = mktime(1, 08, 0, 9, 20, 2009);
$name = "my 20th birthday";
converttime($open, $name);
?>
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47582
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47582&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47582&report=yes
Search -- http://master.php.net/manage/user-notes.php