Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Searching between dates

Problem with start and end dates



7:52 pm on Jul 22, 2006 (gmt 0)

10+ Year Member

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.


8:19 pm on Jul 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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'


8:44 pm on Jul 22, 2006 (gmt 0)

5+ Year Member

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

OOPS, I just read the post above



Featured Threads

Hot Threads This Week

Hot Threads This Month