Find Intersection of Two Date Ranges

Say you have a database of events that span multiple days and you want to filter all events between a certain date range. At first I had this giant mess of this AND that OR this AND that… until I found this:

NOT (range1_start > range2_end OR range1_end < range2_start)

That freakin’ rules.

Filed under  //   programming   sql  

Comments [0]