homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Searching between dates
Problem with start and end dates

10+ Year Member

Msg#: 3018722 posted 7:52 pm on Jul 22, 2006 (gmt 0)

I'm trying to create a SQL query (for MySQL) that will return all events that take place on a particular date.

So far, Ive done the obvious, and compiled the following:

SELECT * FROM events WHERE start_date>='20060720' AND finish_date2<='20060724'

(Dates are year/month/day)

This works great if the start date and end date fall between these two dates.

However, let's assume that the start date of an event is 20060719, and the finish date is 20060725. The event is obviously taking place in the original SQL query, however, it won't return the event, as it appears to fall outside the dates specified.

What I would like to do is to turn the SQL around so that it would read...

SELECT * FROM events WHERE 20060723 BETWEEN start_date AND finish_date

...which cannot be done, obviously.

Does anyone have a solution to this problem?

Thanks a bunch, in advance.



WebmasterWorld Senior Member 10+ Year Member

Msg#: 3018722 posted 8:19 pm on Jul 22, 2006 (gmt 0)

I guess you want to know which events are active between dates.

Is this what you mean?

SELECT * FROM events WHERE start_date>='20060723' or finished_date <='20060723'


5+ Year Member

Msg#: 3018722 posted 8:44 pm on Jul 22, 2006 (gmt 0)

Erm, why don't you use "OR" instead of "AND"

OOPS, I just read the post above


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved