TinyPortal
Development => Block Codes => Topic started by: stormlrd on November 15, 2006, 02:06:57 PM
I figured I'd go ahead and share this with everyone. Basically it will countdown to specific dates and you can manipulate it in different ways for different things to happen.
it is in php
<?php
///xmas countdown
function formatetimestamp($until){
$now = time();
$difference = $until - $now;
$days = floor($difference/86400);
$difference = $difference - ($days*86400);
$hours = floor($difference/3600);
$difference = $difference - ($hours*3600);
$minutes = floor($difference/60);
$difference = $difference - ($minutes*60);
$seconds = $difference;
$output = " $days Days, $hours Hours, and $minutes Minutes GMT until Christmas Day";
return $output;
}
?>
what to send and get output
<?php
$xmas = mktime(0,0,0,12,25,date('Y'));
$down_count = formatetimestamp($xmas);
//output: e.g "You have to wait 162 Days, 4 Hours, 38 Minutes and 46 Seconds until this Day";
?>
How i set one up:
<?php
if(time() < mktime(0,0,0,12,25,date('Y')))
echo $down_count;
else
echo 'Have a Wonderful Christmas and a Happy New Year';
?>
Note I set this up so that when the day arrived it gave you a new message, also because the year is setup to pull the current year once the new year begins the counter will start over. This will work for whatever day your trying to setup for.
Hope everyong enjoys it and its potentials
~Storm
Thanks for sharing StormLrd :up:
thanks for the cool snippet :D :up:
welcome its come in handy for several time/date related snippets