Re: Date Range Question...
| From: | 1LT John W. Holmes | Date: | Tue, 04 Feb 2003 16:04:14 +0000 |
| Subject: | Re: Date Range Question... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25424@lists.php.net to get a copy of this message | ||
> I am working on an app that needs to post information to a website
> based on date. The tricky part for me is that the date is a range that
> spans either 2 or 3 days. I want the web page to dynamically populate
this
> information based on a query. The query will look something like this:
> mysql("Calendar2","SELECT StartDate, StopDate, LocationID FROM
> phpCalendar_Daily WHERE StartDate=CURDATE() ")
>
> My question is say for example the StartDate is actually Jan. 1.
> The page is accessed on Jan. 2 or Jan. 3... The StartDate for the next
> entry is Jan. 4. How do I write this query to select the proper entry?
In
> doing some research, it appears that a MySQL "SELECT CASE" might do the
> trick, but I have never used this before. The other option I can envision
> is using PHP to handle the login and simply running the query, testing the
> result, if NULL, run the query again with CURDATE(-1).
> Any hints, ideas, or suggestions would be most appreciated. Thanks
> in advance.
If I understand you correctly, I think you could use something like this:
SELECT StartDate, StopDate, LocationID FROM phpCalendar_Daily WHERE
StartDate BETWEEN CURDATE() AND CURDATE() - INTERVAL $x DAY
Where $x is 2 or 3, depending on your case.
---John Holmes...