Re: Date comparison going wrong, wrong, wrong

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11-11-2012 22:47, Jim Giner wrote:
Besides the minor fact that the code has syntax errors, the problem with
it is your if is backwrads.  The facts are: today is less than end date,
so your if should show "The show has ended" since you are asking if
today IS GREATER than the end date.

BTW - this is the code I used to test out your process:

<?
$dt_format = "D, M jS, Y g:i:s a";
$todaydate = date($dt_format);
$showenddate = strtotime("11/18/12 16:00:00");
if ($todaydate > $showenddate)
    echo "The date of the show has not yet arrived";
else
    echo "The show has ended";


Not only is the logic wrong, but date returns a string, while strtotime returns an int. Comparing those two to eachother is just... wrong.
Comparing 2 integers and saying one is bigger than the other: ok
Comparing a string and an integer, saying one is bigger than the other: recipe for failure.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux