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?
[SOLVED] Countdown Script
[SOLVED] Countdown Script
Last edited by CMSmonkey on Sat Apr 04, 2009 1:16 am, edited 1 time in total.
Re: Countdown Script
Try this UDT called "my_countdown":
You call it in your page like:
{my_countdown year='2009' month='4' day='5' hour='17' minute='0'}
Nullig
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;
{my_countdown year='2009' month='4' day='5' hour='17' minute='0'}
Nullig
Re: Countdown Script
Excellent! That worked.
Thanks.
Thanks.
Re: [SOLVED] Countdown Script
Hi folks
Total noob to php & CMSMS
Were do I put this code?
tia
w
Total noob to php & CMSMS

Were do I put this code?
tia
w
Re: [SOLVED] Countdown Script
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.wilse wrote: Were do I put this code?
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
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
Re: [SOLVED] Countdown Script
Thanks for that Coldman, worked a treat!
w
w