A
A
ayurganov2010-12-04 15:37:08
SQL
ayurganov, 2010-12-04 15:37:08

[SQL] Check if one date range lies within another

Good afternoon.
Please help me write a SQL query.

There are two dates.
You need to check that the interval between these data does not fall into the date interval in the database table. And also that the date interval in the table does not fall within the interval between these dates.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xdenser, 2010-12-04
@xdenser

well, like this

select * from table t
where 
not
(
{$fromDate} between t.date1 and t.date2
or
{$toDate} between t.date1 and t.date2
)
</sql>

X
XuMiX, 2010-12-04
@XuMiX

declare date1 datetime;
declare date2 datetime;
set @date1 = '2010-12-03';
set @date2 = '2010-12-07';
select * from table t where t.date not between @date1 and date2;

C
collapse, 2010-12-04
@collapse

`start` < #end AND `reservation`.`end` > #start
Where #start and #end respectively is your range

A
apangin, 2010-12-04
@apangin

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)
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question