Hello,
I'm trying to manage appointment conflicts in a calendar application.
Here is the table kind of format that I use with sample data:
Code:
+-----------------+
| calendar_events |
+------------+-------+-------+---------------------+
| date | start | end | location |
+------------+-------+-------+---------------------+
| 2006-11-22 | 10:30 | 12:00 | Paris Montparnasse |
| 2006-11-22 | 14:00 | 15:00 | Paris StLazarre |
+------------+-------+-------+---------------------+
The user give start and end times (let's say given_start and given_end)
The aim is to find if there is any conflict.
I made this query:
Code:
SELECT
start AS "start",
end AS "end",
location AS "location"
FROM
calendar_events
WHERE
date = "2006-11-22"
AND (
(
[$given_start] > start
AND [$given_start] < end
)
OR
(
[$given_end] > start
AND [$given_end] < end
)
OR
(
[$given_start] < start
AND [$given_end] > end
)
OR [$given_start] = tup.start_time
OR [$given_end] = tup.end_time
)
ORDER BY
tup.start_time
Isn't it an easiest way ?