MySQL - Check if 2 start and end parameter is not between start and end in database record

Solution 1:

It seems that you wish to detect collisions between intervals and return a final count if any with the passed parameters.

So, we would be checking if any event occurs after the passed in params' event has ended or if any event only occurs and ends before the passed in params' event starts. This ensures no collision. We will negate(!) the result to say there is a collision(if any).

You can follow the below format:

select * 
from tasks 
WHERE !(start >= {end_parameter_time} OR end <= {start_parameter_time})

More precisely for your case/example, it would be:

select * 
from tasks 
WHERE !(start >= '2022-01-19 07:00:00' OR end <= '2022-01-19 06:00:00')

Online Demo

Solution 2:

The query to test if date range [@d1, @d2) overlaps date range [start, end) is as follows:

SELECT *
FROM tasks
WHERE @d2 > start
AND   @d1 < end