Re: Date comparison going wrong, wrong, wrong
| From: | Maciek Sokolewicz | Date: | Mon, 12 Nov 2012 06:52:38 +0000 |
| Subject: | Re: Date comparison going wrong, wrong, wrong | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319686@lists.php.net to get a copy of this message | ||
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)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.echo "The date of the show has not yet arrived";elseecho "The show has ended";