Neither will work. Think about it...... If you did 17 - 3 (17th May - 3rd
June) - you get 14. But if you add 14 days from today, you get 31st May,
which is clearly wrong. What if there are 30 days in the month instead of
31? Or 28? Or even more obscurely 29? You cannot rely on this method at
all.
What you need to do here is to get the distance between days in real terms.
I suggest using mktime(); - that way you can subtract dates over a long
timespan.
<?
$today = date("Y-m-d");
list($year, $month, $day) = explode("-", $today);
$date_today = mktime(0, 0, 0, $month, $day, $year);
$school_out = mktime(0, 0, 0, 07, 21, 2001);
$difference = $school_out - $date_today;
$days = $difference / 86400;
if ($date_today > $school_out) {
echo "We're already on holiday!";
} else {
echo $days . " days to go!";
}
?>
Where $school_out = 21st July, 2001.
86400 is the number of seconds in a day.
Things would get more complicated with hours and seconds, but you get the
idea :) Note that in this instance, $difference / 86400 will always be an
exact division.
James
""Taylor, Stewart"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> <?
>
> $date = date ("d");
> $math = 24 - $date;
> if ($date == 24); { <---- '=' shoud be '=='
> echo "<FONT SIZE=4 FACE=ARIAL COLOR=#808080>SCHOOL'S OUT FOR
SUMMER!!!
> *guitar ballad*</font>";
> } else {
> echo "<FONT SIZE=4 FACE=ARIAL COLOR=#808080>Only $math days until
> school's out!!! w00p w00p!</font>";
> }
> ?>
>
> -----Original Message-----
> From: chris herring [mailto:[EMAIL PROTECTED]]
> Sent: 17 May 2001 09:56
> To: [EMAIL PROTECTED]
> Subject: [PHP] UGH
>
>
> This is really bugging me. I don't see any reason why it shouldn't work,
yet
> it doesn't.
>
> <?
>
> $date = date ("d");
> $math = 24 - $date;
> if ($date = 24); {
> echo "<FONT SIZE=4 FACE=ARIAL COLOR=#808080>SCHOOL'S OUT FOR
SUMMER!!!
> *guitar ballad*</font>";
> } else {
> echo "<FONT SIZE=4 FACE=ARIAL COLOR=#808080>Only $math days until
> school's out!!! w00p w00p!</font>";
> }
> ?>
>
> any help is appreciated
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]