sujal sujal - 1 month ago 8
MySQL Question

How to check a dates of a date range lies in between two dates in mysql query

I have a date range like

date from=2011-10-14 & date to=2011-10-20

if I have another date ranges

like

- 2011-10-11 - 2011-10-15
- 2011-10-11 - 2011-10-21
- 2011-10-15 - 2011-10-21
- 2011-10-15 - 2011-10-19
- 2011-10-21 - 2011-10-26


I want sql query which shows only the date range whose dates lies in between above
(2011-10-14 & date to=2011-10-20)
date range.

Here only
2011-10-21 - 2011-10-26
does not lies in
date from=2011-10-14 & date to=2011-10-20


Result must show

- 2011-10-11 - 2011-10-15
- 2011-10-11 - 2011-10-21
- 2011-10-15 - 2011-10-21
- 2011-10-15 - 2011-10-19


these dates

Hope you understand what I am asking.

Answer
date_from < '2011-10-20' AND date_to > '2011-10-14'