Web Hosting Talk







View Full Version : christmas day countdown


michael-lane
05-17-2006, 07:25 PM
<?php
$christmas = mktime(0, 0, 0, 25, 12, 2006);
$time = time();
echo round($christmas-$time/86400). " days.";
?>
Why won't this script work for me? The script is based on tutorials i've read and on my own previous php manual reads but it won't work. Instead of showing the amount of days till christmas it returns this long number of like 10 digits which is obviously incorrect. Can someone note where i'm going wrong and how. I think its on the fourth line but I cant be sure.

dollar
05-17-2006, 07:29 PM
Order of Operations :)


<?php
$christmas = mktime(0, 0, 0, 25, 12, 2006);
$time = time();
echo round(($christmas-$time)/86400). " days.";
?>

Not the ()'s around $christmas-$time. Order of operations says that division is done before addition and subtraction, so your fuction was doing the following:

Time / 86400

and then subtracting that answer from the value in $chrismas.