Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

date

mysql

range

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.

like image 793
sujal Avatar asked Jul 02 '26 07:07

sujal


1 Answers

date_from < '2011-10-20' AND date_to > '2011-10-14'
like image 191
Mikael Eriksson Avatar answered Jul 04 '26 20:07

Mikael Eriksson