Countdown

Posted under » PHP on 21 October 2009

Countdown is about date and time. It is important to set the correct time zone.

date_default_timezone_set("Asia/Singapore");

Today's date is

date("j F  Y, g:i a") 

OK so here is the function.

function countdown($year, $month, $day, $hour, $minute, $event)
{
global $kontent;
  // 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;
  
 // floor - returns the next lowest integer value by rounding down value if necessary.
  $days = floor($difference/60/60/24);
 // Note that NOT everymonth have 30 days but it is just an approximation
  $months = floor($days/30);
  $days_left = floor($days - $months*30);
 //   $hours_left = floor(($difference - $days*60*60*24)/60/60);
//   $minutes_left = floor(($difference - $days*60*60*24 - $hours_left*60*60)/60);

  // OUTPUT
$kontent .= "

Countdown date: ".$event." / " .date("j F Y",$the_countdown_date)."
"; $kontent .= "Days left : ".$days." days "; if ($months > 0) { $kontent .= "/ ". $months." Months & "; $kontent .= $days_left." days left

"; } else { $kontent .= "";} }

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data