Community Documentation

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

Last updated June 1, 2009. Created by Dublin Drupaller on June 27, 2005.
Edited by bekasu, pwolanin. Log in to edit this page.

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>";
}
?>

About this page

Drupal version
Drupal 4.5.x or older, Drupal 4.6.x, Drupal 5.x

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here