Check if date interval is included in another date interval (MySQL)
I need to check in MySQL to see if a date interval is included in another
date interval.
To explain better my issue: I have an event management module. If we have
an event that was added like this:
start date : '2013-09-09 08:00:00'
end date : '2013-09-09 10:00:00'
and now I want to add another event that's like this:
case A:
start date : '2013-09-09 09:00:00'
end date : '2013-09-09 11:00:00'
OR like this :
case B:
start date : '2013-09-09 07:00:00'
end date : '2013-09-09 12:00:00'
I shouldn't be able to do this because an event was already added in that
time interval (08-10)
For the first example (case A), I solved the issue by doing this :
SELECT * FROM `events` as e
where
'2013-09-09 08:00:00' between e.ev_date_start and e.ev_date_end --
date start
OR
'2013-09-09 11:00:00' between e.ev_date_start and e.ev_date_end --
date end
But for the second case (case B) I'm having trouble figuring it out...
No comments:
Post a Comment