homepage Welcome to WebmasterWorld Guest from 54.205.106.111
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Searching between dates
Problem with start and end dates
Chris_H




msg:3018724
 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.

 

Frank_Rizzo




msg:3018739
 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'

vite_rts




msg:3018762
 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

cheers

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