[SQL] to Check whether one date range to another


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Good afternoon.
Please help me to create SQL query.

There are two dates.
You need to check that the interval between these data does not fall in the date interval in the database table. And also that date range in the table falls in the interval between these dates.
by | 10 views

4 Answers

0 like 0 dislike
well
\r
select * from table t where not ( {$fromDate} between t.date1 and t.date2 or {$toDate} between t.date1 and t.date2 ) 
by
0 like 0 dislike
declare date1 datetime;
declare date2 datetime;
set @date1 = '2010-12-03';
set @date2 = '2010-12-07';
\r
select * from table t where t.date not between @date1 and date2;
by
0 like 0 dislike
`start` < #end AND `reservation`.`end` > #start
Where #start and #end, respectively, of your range
by
0 like 0 dislike
SELECT * FROM dates d WHERE NOT ( (my_from < d.date_from AND my_to < d.date_from) OR (my_from > d.date_to AND my_to > d.date_to) ) 
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 3, 2019 by Romario21
110,608 questions
257,186 answers
0 comments
27,842 users