Testing for overlapping/intersecting date ranges
How do we test whether one date range intersects/overlaps another date range?
There are six possible combinations to consider.
- entire date range falls outside of our specified range (too early)
- date partially falls partially inside our range (start date out of range)
- date range encompasses our range entirely
- date falls entirely inside our range
- date partially falls inside our range (end date out of range)
- date falls outside our specified range (too late)
The hard way to do this is to handle cases 2, 3, 4 and 5 using an OR criteria, since each criteria requires two checks, this results in total of 8 tests.
The easy way is to handle cases 1 and 6, which only requires a single test for each.
Not (EndDate '2010-03-15:00:00:00')
which can be simplified to
EndDate => '2010-01-15:00:00:00' And StartDate =< '2010-03-15:00:00:00'
About this entry
You’re currently reading “ Testing for overlapping/intersecting date ranges ,” an entry on Chui's Counterpoint
- Published:
- 8.4.10 / 10am
- Category:
- General

No comments
Jump to comment form | comments rss [?]