0
Follow
2
View

Select where datetime start greater than and end less than

dxydiedre 注册会员
2023-01-25 11:31

Looking at the entry in your database and the query you're using, it seems like you're actually looking for a date interval query i.e. a query that checks if [2021-10-01 02:00:00, 2021-10-01 08:00:00) overlaps [2021-09-24 17:00:00, 2021-10-01 08:00:00) somehow.

SELECT *
FROM `oncall`
WHERE @d2 > `start` AND `end` > @d1

-- replace @d1 and @d2 with actual values

Note that this query works for all kinds of overlap. For example if you have this pair of dates in your database:

2021-10-11 | 2021-10-15

then all of these input pairs will match:

2021-10-01 | 2021-10-12
2021-10-14 | 2021-10-20
2021-10-01 | 2021-10-20
2021-10-11 | 2021-10-14

About the Author

Question Info

Publish Time
2023-01-25 11:31
Update Time
2023-01-25 11:31