TinyPortal

Development => Block Codes => Topic started by: stormlrd on November 15, 2006, 02:06:57 PM

Title: Adding a count down
Post 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
Code (function) Select
<?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

Code (setting date and output) Select
<?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:

Code (example) Select
<?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
Title: Re: Adding a count down
Post by: rebelrose on November 16, 2006, 03:03:33 AM
Thanks for sharing StormLrd  :up:
Title: Re: Adding a count down
Post by: akulion on November 16, 2006, 09:57:18 AM
thanks for the cool snippet :D :up:
Title: Re: Adding a count down
Post by: stormlrd on November 16, 2006, 10:16:29 AM
welcome its come in handy for several time/date related snippets