search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Testing for Overlapping Events with SQL

Asked by Dave Abad
11 years ago.
I know this is way sort of off topic but like the rest of you I'm developing a time / event scheduling app so I though I might save you some time and post this thing I've been banging my head against the wall working on. Namely since my app is being used to keep track off billable time I needed a way to make sure new events do not overlap any existing ones in my database.

Here's the SQL...

SELECT eventid from events WHERE(NOT((event_end < '" & newEventStartDate & "')
OR (event_start > '" & newEventEndDate & "')));"

Hope you find this helpful.

Dave
Comment posted by Dan Letecky
11 years ago.
Thanks for sharing the code, Dave!
Answer posted by Tim Daldini
9 years ago.

As far as I know, without the NOT that would be.

SELECT eventid from events WHERE((event_end >= '" & newEventStartDate & "')
AND (event_start <= '" & newEventEndDate & "'));"

This is exactly the same

Comment posted by Dan Letecky
9 years ago.

Thanks, Tim!

Comment posted by Stepahnie
6 years ago.

Does this work for recurring events to?

This question is more than 6 months old and has been closed. Please create a new question if you have anything to add.