title: Mysql: select by date intersection, not between
body: <p>I have an ordering system. In db I have table with blocked dates for ordering system (when customer wants to turn it off for some reason like vacation).
  Ordering system allows to order in time period for next four weeks from actual date. </p>
  
  <p>As input I have in PHP <code>$startDT</code> and <code>$endDT</code>
  Each blocking in db have its <code>valid_from</code> and <code>valid_to</code> columns</p>
  
  <p>Problem is with long-term blockings (e.g. month), when valid_from and valid_to are out of time period for create order.</p>
  
  <p><a href="https://i.stack.imgur.com/FFC0z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FFC0z.png" alt="enter image description here"></a></p>
  
  <p>For short-term and mid-term blockings nicely works this code:</p>
  
  <pre><code>SELECT * FROM `vk_blocking` WHERE (`valid_from` BETWEEN '$startDt' AND '$endDt') OR (`valid_to` BETWEEN '$startDt' AND '$endDt')
  </code></pre>
  
  <p>But in shown long-term (ID:3), there is on <code>valid_from</code> or <code>valid_to</code> between <code>$startDt</code> and <code>$endDt</code></p>
  
  <p>How to ask MySQL to return also for long-term period? Is there something like</p>
  
  <pre><code>SELECT * FROM `vk_blocking` WHERE DATERANGE(`valid_from`, `valid_to`) INTERSECTS DATERANGE($startDt, $endDt)
  </code></pre>