Hi guys,
I'm having a bit of trouble finding querying a table with "start" and "end" dates.
Consider the following tables;
Event table
------------
id | eventName
1 Event 1
2 Event 2
Event Bookings Table
---------------------
id | eventId | bookingStartDate | bookingEndDate |
1 1 01/05/08 14/05/08
2 2 07/05/08 12/05/08
3 2 08/06/08 24/06/08
What I need to do is find all events that are NOT booked between two given dates; for example I might enter the dates 20/05/2008 to 01/06/2008 and would expect to get only event 1 (because event 2 is not fully available during the date period).
Here is where it gets tricky; I also need to add flexibility to this. So for example, if the date range entered is 20/05/2008 to 01/06/2008 and the flexibility selected was 2 days, then it would need to check 2 days either side of the date range as follows;
18/05/2008 - 30/05/2008 (inclusive)
OR
19/05/2008 - 31/05/2008 (inclusive)
OR
20/05/2008 - 01/06/2008 (inclusive)
OR
21/05/2008 - 02/06/2008 (inclusive)
OR
22/05/2008 - 03/06/2008 (inclusive)
Ideally, I would like to keep the query to one single MySQL query (if possible).
If anyone could help, I would be most grateful.
Kind Regards
Webbo
I'm having a bit of trouble finding querying a table with "start" and "end" dates.
Consider the following tables;
Event table
------------
id | eventName
1 Event 1
2 Event 2
Event Bookings Table
---------------------
id | eventId | bookingStartDate | bookingEndDate |
1 1 01/05/08 14/05/08
2 2 07/05/08 12/05/08
3 2 08/06/08 24/06/08
What I need to do is find all events that are NOT booked between two given dates; for example I might enter the dates 20/05/2008 to 01/06/2008 and would expect to get only event 1 (because event 2 is not fully available during the date period).
Here is where it gets tricky; I also need to add flexibility to this. So for example, if the date range entered is 20/05/2008 to 01/06/2008 and the flexibility selected was 2 days, then it would need to check 2 days either side of the date range as follows;
18/05/2008 - 30/05/2008 (inclusive)
OR
19/05/2008 - 31/05/2008 (inclusive)
OR
20/05/2008 - 01/06/2008 (inclusive)
OR
21/05/2008 - 02/06/2008 (inclusive)
OR
22/05/2008 - 03/06/2008 (inclusive)
Ideally, I would like to keep the query to one single MySQL query (if possible).
If anyone could help, I would be most grateful.
Kind Regards
Webbo