[SOLVED] Countdown Script

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
CMSmonkey
Power Poster
Power Poster
Posts: 290
Joined: Thu Nov 27, 2008 4:58 pm

[SOLVED] Countdown Script

Post 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?
Last edited by CMSmonkey on Sat Apr 04, 2009 1:16 am, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Countdown Script

Post 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
CMSmonkey
Power Poster
Power Poster
Posts: 290
Joined: Thu Nov 27, 2008 4:58 pm

Re: Countdown Script

Post by CMSmonkey »

Excellent! That worked.

Thanks.
wilse
Forum Members
Forum Members
Posts: 15
Joined: Fri Dec 10, 2010 4:15 pm

Re: [SOLVED] Countdown Script

Post by wilse »

Hi folks

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

tia

w
Coldman
Power Poster
Power Poster
Posts: 318
Joined: Sun Jun 22, 2008 5:33 am

Re: [SOLVED] Countdown Script

Post 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!
Important Code of Conduct
Why don't use CMSMS Docs or search?
Do you read Help?
Admin for Swedish Translations Team
Moderator Swedish Forum
After your problem is solved, push the green button
wilse
Forum Members
Forum Members
Posts: 15
Joined: Fri Dec 10, 2010 4:15 pm

Re: [SOLVED] Countdown Script

Post by wilse »

Thanks for that Coldman, worked a treat!

w
Post Reply

Return to “Modules/Add-Ons”