TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 03:17:50 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 54
  • Total: 54

Adding a count down

Started by stormlrd, November 15, 2006, 02:06:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stormlrd

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

rebelrose

Thanks for sharing StormLrd  :up:

akulion

thanks for the cool snippet :D :up:

stormlrd

welcome its come in handy for several time/date related snippets