Countdown (x) days to a specific date and display a dynamic message

Last modified: June 1, 2009 - 03:34

PLEASE NOTE! The following snippet is user submitted. Use at your own risk!

This countdown snippet uses only standard PHP functions, so should work with any version of Drupal. However, if you are not in the same timezone as your server, this code may need to be adjusted.

<?php
/**
* This php snippet displays (x) days left to a specific event
*
*
* Change the values for keyMonth, keyDay and keyYear to suit
*
*
* Tested and works with drupal 4.6 and 4.5 and 5.7
*/

$keyMonth = 7;
$keyDay = 14;
$keyYear = 2005;

$month = date(F);
$mon = date(n);
$day = date(j);
$year = date(Y);
$hours_left = (mktime(0,0,0,$keyMonth,$keyDay,$keyYear) - time())/3600;
$daysLeft = ceil($hours_left/24);
$z = (string)$daysLeft;
if (
$z > 1) {
print
"There are <font size=\"4\" color=\"red\">";
print
$z;
print
"</font> days left until whatever happens</p>";
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.