I'm trying to return MySQL rows when the start_date and end_date period falls within a date range, either completely or partially.
Here's the SQL I'm using at the moment.
SELECT
start_date,
end_date,
id
FROM
employee_leave
WHERE
DATE(start_date) >= :start_date_range
AND DATE(end_date) <= :end_date_range;
This works fine to return rows that fall wholly within the specified range but it needs to also return rows that are partially within the range too.
Example, start_date_range = 2015-07-04 end_date_range = 2015-07-15
If I have the following rows they should all be returned:
- start_date = 2015-07-05, end_date = 2015-07-10
- start_date = 2015-07-01, end_date = 2015-07-10
- start_date = 2015-07-01, end_date = 2015-07-20
- start_date = 2015-07-11, end_date = 2015-07-20