Re: Date comparison going wrong, wrong, wrong

From: Date: Sun, 11 Nov 2012 18:49:31 +0000
Subject: Re: Date comparison going wrong, wrong, wrong
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-319677@lists.php.net to get a copy of this message
On 11 Nov 2012, at 18:30, "Terry Ally (Gmail)" <terryally@gmail.com> wrote: > I am having a problem with comparing time. I am using the following: > > $todaydate = date("D, M jS, Y g:i:s a"); > $showenddate = date("D, M jS, Y g:i:s a", > strtotime($showsRecord['end_date'])); The date function returns a string. > if ($todaydate > $showenddate): > echo "The date of the show has not yet arrived"; > else: > echo "The show has ended"; > endif; So here you are comparing two strings; PHP has no idea they are dates. > The problem that I am encountering is that PHP is rendering the reverse of > the equation. For example: > > If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*, > the message that I am getting is *the show has ended* which is wrong. A > test example is at http://www.lakesidesurrey.co.uk/test.php. > > You can also me what I am doing wrong? Compare timestamps instead, i.e. time() for the current time, and what you get back from strtotime for the end date. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/

« previous php.general (#319677) next »