note 47582 deleted from function.time by aidan
| From: | aidan@php.net | Date: | Sat, 08 Oct 2005 01:04:30 +0000 |
| Subject: | note 47582 deleted from function.time by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96621@lists.php.net to get a copy of this message | ||
Note Submitter: xaxisx at gmail dot com
----
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);
?>