Log in

View Full Version : PHP Countdown only changing in the afternoon and not midnight



Ryan Fitton
02-07-2009, 08:43 PM
Hi, my PHP countdown script counts down the number of days until a custom date, i have a problem though the number of days in the countdown only change after 12:00 in the afternoon, instead i want it to change at 12:00 midnight. Is it possible to do this?

Here is the code:


<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('GMT');

$custom_date = strtotime('15 February 2009');
$now = time();
$timeleft = $custom_date-$now;
$daysleft = round((($timeleft/24)/60)/60); //probably...
echo "$daysleft days until New York trip";
?>

techietim
02-07-2009, 09:14 PM
Instead of the round function, use the floor function.

Ryan Fitton
02-08-2009, 08:42 PM
Thanks techietim, it work great now :)