Re: UGH

From: Date: Thu, 17 May 2001 10:29:14 +0000
Subject: Re: UGH
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53205@lists.php.net to get a copy of this message
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"" <Stewart.Taylor@uk.thalesgroup.com> wrote in message news:2B25A9C95DC8D411BBE500508BB19239515D05@ntslxch1.int.rdel.co.uk... > <? > > $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:chrisherring@subdimension.com] > Sent: 17 May 2001 09:56 > To: php-general@lists.php.net > 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: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53205) next »