Reputation: 1621
I have a table with the following fields.
tbl_events
====================
id
title
start -datetime
end -datetime
status
I have the following data in that table.
tbl_events
========================
1
Test Title 1
2015-11-14 10:30:00
2015-11-15 15:00:00
active
2
Test Title 2
2015-10-31 00:00:00
2015-11-04 00:00:00
active
3
Test Title 1
2015-11-30 00:00:00
2015-12-1 00:00:00
active
I am trying to bring up a calendar and when i pull up the month of november i want to show all these events since they either have a start date or an end date in november. I have the following query which i can get to work with only one field but not sure how to do it when i have a start and end field.
SELECT * FROM tbl_events WHERE(start BETWEEN '2015-11-01 00:00:00 AND 2015-11-31 23:59:59)"
Upvotes: 0
Views: 23
Reputation: 1270401
An event overlaps in November if it ends one or after the 1st and starts one or before December begins:
Here is one way to express this:
SELECT *
FROM tbl_events
WHERE end >= '2015-11-01' and start < '2015-12-01';
Upvotes: 2