Re: Date comparison going wrong, wrong, wrong
| From: | Stuart Dallas | Date: | Sun, 11 Nov 2012 19:11:36 +0000 |
| Subject: | Re: Date comparison going wrong, wrong, wrong | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319681@lists.php.net to get a copy of this message | ||
Please include the list when replying.
On 11 Nov 2012, at 19:08, "Terry Ally (Gmail)" <terryally@gmail.com> wrote:
> What I want is the reverse.
>
> I want that if people attempt to access the show page after the show has ended that it triggers
> an error which takes it to another page. The actual conditional statement is as follows (which I
> will replace with timestamp):
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
> if ($todaydate > $showenddate) {
> header( 'Location: eventdetails_error.php' ) ;
> }
This is what you have:
if ($todaydate > $showenddate):
echo "The date of the show has not yet arrived<br>";
else:
echo "The show has ended<br>";
endif;
That says: if the current time is later than the end date of the show, tell them the date of the
show hasn't arrived yet.
What you mean is: if the current time is later than the end of the show, tell them the show has
ended.
if ($todaydate < $showenddate):
echo "The date of the show has not yet arrived<br>";
else:
echo "The show has ended<br>";
endif;
It's a simple logic error.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
> On 11 November 2012 19:04, Stuart Dallas <stuart@3ft9.com> wrote:
> On 11 Nov 2012, at 19:00, "Terry Ally (Gmail)" <terryally@gmail.com> wrote:
>
> > Hi Shiplu and Stuart,
> >
> > Comparing timestamps was my first option. I've reinstated it. Have a look
> > at http://www.lakesidesurrey.co.uk/test.php
(show_source included) and you
> > will see that PHP is still outputting the wrong thing.
> >
> > I just can't figure out what's wrong.
>
> Your comparison is backwards:
>
> if ($todaydate > $showenddate):
>
> should be
>
> if ($todaydate < $showenddate):
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
> > On 11 November 2012 18:48, shiplu <shiplu.net@gmail.com> wrote:
> >
> >> You can always use timestamp which is integer.
> >>
> >> $todaydate = time();
> >> $showenddate = strtotime($showsRecord['end_date']);
> >>
> >>
> >> On Mon, Nov 12, 2012 at 12:30 AM, Terry Ally (Gmail) <terryally@gmail.com>wrote:
> >>
> >>> Hi all,
> >>>
> >>> 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']));
> >>>
> >>> if ($todaydate > $showenddate):
> >>> echo "The date of the show has not yet arrived";
> >>> else:
> >>> echo "The show has ended";
> >>> endif;
> >>>
> >>> 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?
> >>>
> >>> Thanks
> >>> Terry
> >>>
> >>
> >>
> >>
> >> --
> >> Shiplu.Mokadd.im
> >> ImgSign.com | A dynamic signature machine
> >> Innovation distinguishes between follower and leader
> >>
> >>
> >
> >
> > --
> > *Terry Ally*
> > Twitter.com/terryally
> > Facebook.com/terryally
> > ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> > To print or not to print this email is the environmentally-searching
> > question!
> > Which has the highest ecological cost? A sheet of paper or constantly
> > switching on your computer and connecting to the Internet to read your
> > email?
>
>
>
>
> --
> Terry Ally
> Twitter.com/terryally
> Facebook.com/terryally
> ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
> To print or not to print this email is the environmentally-searching question!
> Which has the highest ecological cost? A sheet of paper or constantly switching on your
computer and connecting to the Internet to read your email?
>