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.

  1. entire date range falls outside of our specified range (too early)
  2. date partially falls partially inside our range (start date out of range)
  3. date range encompasses our range entirely
  4. date falls entirely inside our range
  5. date partially falls inside our range (end date out of range)
  6. 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