Page 1 of 1

[SOLVED] Countdown Script

Posted: Fri Apr 03, 2009 10:59 pm
by CMSmonkey
Hi Everyone,
I need to add a countdown to date script on my site.

I found the following PHP script, but I can't seem to get it to work on the site.  I put it in as a UDT.  When I preview my page with it on there, from where I added the tag and on down - it is blank.  I figure that it is probably some further customization I need to do to it so that it can work on the CMSMS site, I am just not sure what to do.

Here it is:
[php]
function countdown($year, $month, $day, $hour, $minute)
{
  // make a unix timestamp for the given date
  $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

  // get current unix timestamp
  $today = time();

  $difference = $the_countdown_date - $today;
  if ($difference < 0) $difference = 0;

  $days_left = floor($difference/60/60/24);
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
 
  // OUTPUT
echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
[/php]


Any suggestions?

Re: Countdown Script

Posted: Sat Apr 04, 2009 1:00 am
by Nullig
Try this UDT called "my_countdown":

Code: Select all

$year = $params['year'];
$month = $params['month'];
$day = $params['day'];
$hour = $params['hour'];
$minute = $params['minute'];
$countdown = "There are ";

$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year);

$today = time();

$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;

$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

$countdown .= $days_left." days ";
$countdown .= $hours_left." hours and ";
$countdown .= $minutes_left." minutes left.";

echo $countdown;
You call it in your page like:

{my_countdown year='2009' month='4' day='5' hour='17' minute='0'}

Nullig

Re: Countdown Script

Posted: Sat Apr 04, 2009 1:16 am
by CMSmonkey
Excellent! That worked.

Thanks.

Re: [SOLVED] Countdown Script

Posted: Fri Dec 10, 2010 4:18 pm
by wilse
Hi folks

Total noob to php & CMSMS ???
Were do I put this code?

tia

w

Re: [SOLVED] Countdown Script

Posted: Fri Dec 10, 2010 5:14 pm
by Coldman
wilse wrote: Were do I put this code?
Copy and paste the code above in  Extensions -> User Defined Tags and call it my_countdown . In your template or page add {my_countdown year='YOURYEAR' month='YOURMONTH' day='YOURDAY' hour='YOURHOUR' minute='YOUMINUTE'} hit Submit.
Done!

Re: [SOLVED] Countdown Script

Posted: Fri Dec 10, 2010 6:28 pm
by wilse
Thanks for that Coldman, worked a treat!

w