Last active
August 29, 2015 14:10
-
-
Save rahman541/b6ca87185a75e9136f36 to your computer and use it in GitHub Desktop.
To check time if it avialble in mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assuming Date Range 1 :: User Input | |
Date Range 2 :: Database Row | |
Intersection | |
Date Range 1 | |>----------------------<| | |
Date Range 2 | |>------------------------<| | |
where Range1Start <= Range2End and Range1End >= Range2Start | |
Range 1 in Range 2: | |
Date Range 1 | |>-------------<| | |
Date Range 2 | |>------------------------<| | |
where Range1Start >= Range2Start and Range1End <= Range2End | |
Range 2 in Range 1: | |
Date Range 1 | |>----------------------<| | |
Date Range 2 | |>-------------<| | |
where Range2Start >= Range1Start and Range2End <= Range1End | |
14:00:00 -> 18:00:00 (Stored In DB) | |
1) 15:00:00 -> 19:00:00 :: True (intersection date to the left) | |
2) 12:00:00 -> 17:00:00 :: True (intersection date to the right) | |
3) 10:00:00 -> 13:00:00 :: False (before date range 2) | |
4) 19:00:00 -> 21:00:00 :: False (after date range 2) | |
5) 15:00:00 -> 16:00:00 :: True (Subset) | |
6) 13:00:00 -> 19:00:00 :: True (Superset) | |
Sample Sql in #2 :: | |
SELECT * FROM Room WHERE | |
('12:00:00' <= `end_time` AND '17:00:00' >= `start_time`) OR | |
('12:00:00' >= `start_time` AND '17:00:00' <= `end_time`) OR | |
(`start_time` >= '12:00:00' AND `end_time` <= '17:00:00') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment