Web Hosting Talk







View Full Version : Countdown to Tomorrow?


chightech
12-15-2004, 04:36 AM
Hi, I would like to use PHP to countdown, not to a specific date, but to Tomorrow...



I would like it to display in hours:mins:seconds



i'm a newbie, could anyone tell me how I do this?

saghir69
12-15-2004, 06:59 AM
may java will be better for something like this? just search on google for countdown jave code .. they are common.

Vult-r
12-15-2004, 08:01 AM
i made this very quickly for you, seems to work,

this script will count down to 16 december 2004


<?

// date to set counting to..
$day = 16; // day
$month = 12; // month
$year = 2004; // year

// make a timestamp
$dif = (int)((mktime (0,0,0,$month,$day,$year) - time(void)));

// calculate hours, minutes and seconds.
$counthours = intval($dif / 3600);
$dif = $dif % 3600;
$counrminutes = intval($dif / 60);
$dif = $dif % 60;
$countseconds = intval($dif);

// show remaining time
print ("$counthours hours $counrminutes minutes & $countseconds seconds to go..");

?>

Jason.NXH
12-15-2004, 08:47 AM
Once it reaches that date, it starts counting backwards am I correct?

Vult-r
12-15-2004, 10:03 AM
yep .. backwards :/


<?

// date to set counting to..
$day = 16; // day
$month = 12; // month
$year = 2004; // year

// make a timestamp
$dif = (int)((mktime (0,0,0,$month,$day,$year) - time(void)));

if($dif > 0)
{
// calculate hours, minutes and seconds.
$counthours = intval($dif / 3600);
$dif = $dif % 3600;
$countminutes = intval($dif / 60);
$dif = $dif % 60;
$countseconds = intval($dif);

// show remaining time

print ("$counthours : $countminutes : $countseconds to go..");
}
else
{
print ("countdown complete");
}

?>


should be a way to fix that

Jason.NXH
12-15-2004, 10:15 AM
That's better ;)

chightech
12-15-2004, 10:57 AM
thanks, but that's only count down to 16, when it becomes 16, i would like to it to automaticlaly count down to the 17th, and 17 to 18...ect

Thanks for your help.. I have something like this, but it didnt' work:


$days_seens_unix = (int) ( time() / 8400 ) ;
$tomorrow_day_num = $days_seens_unix + 1;

$day = date( "d", $tomorrow_day_num );
$month = date( "m", $tomorrow_day_num );
$year = date( "Y", $tomorrow_day_num );

$tomorrow_begin_time = mktime( 0, 0, $month, $day, $year );
// I'm not shure may be like this
//$tomorrow_begin_time = mktime( 0, 0, $day, $month, $year );

$seconds_to_tomorrow = $tomorrow_begin_time - time();

echo "Tomorrow Countdown: ".date( "bla bla bla", $seconds_to_tomorrow );

Vult-r
12-15-2004, 03:22 PM
try this ..


<?

$days_seens_unix = strtotime("+1 day");
$tomorrow_day_num = $days_seens_unix + 1;

$day = date( "d", $tomorrow_day_num );
$month = date( "m", $tomorrow_day_num );
$year = date( "Y", $tomorrow_day_num );

$tomorrow_begin_time = mktime( 0, 0, 0, $month, $day, $year );
// I'm not shure may be like this
//$tomorrow_begin_time = mktime( 0, 0, $day, $month, $year );

$seconds_to_tomorrow = $tomorrow_begin_time - time();

echo "Tomorrow Countdown: $seconds_to_tomorrow ";

?>


you can make hours days etc yourself i think

(note) this is only server time , for some someone from china this might be a problem