title: booking dates ranges mysql php
body: <p>Again booking system and dates ranges.
  I've read this topic <a href="https://stackoverflow.com/questions/143552/comparing-date-ranges">Comparing date ranges</a> and many others,
  but can't find answer :(</p>
  
  <p>Please see SQLFiddle <a href="http://sqlfiddle.com/#!2/89b2b/2" rel="nofollow noreferrer">http://sqlfiddle.com/#!2/89b2b/2</a></p>
  
  <p>I have booking table, that have <code>ID</code>, <code>ObjectID</code>, <code>PeriodStart</code> and <code>PeriodEnd</code> fields of type <code>DATE</code> in <code>MySQL</code><br>
  My example data looks like this:</p>
  
  <pre><code>(1, 3, '2014-08-07', '2014-08-14'),
  (2, 3, '2014-08-19', '2014-08-23'),
  (3, 2, '2014-08-13', '2014-08-15'),
  (4, 2, '2014-08-19', '2014-08-21');
  </code></pre>
  
  <p>My query dates interval is (<strong>updated</strong>, was <code>$from = '2014-08-14';</code>):</p>
  
  <pre><code>$from = '2014-08-15';
  $to = '2014-08-19'
  </code></pre>
  
  <p>I'd like to get <code>ObjectID</code>s that are <em>free</em> on query dates interval.<br>
  Problem is that, object's <code>2</code> first reservation ends on <code>2014-08-15</code> and we want to make new booking started from <code>2014-08-15</code>. Same thing with ending date <code>2014-08-19</code>. Existing reservations start on this day. It's ok for <code>humans</code> because we calculate date periods as <code>nights</code>, but how to tell same thing to <code>MySQL</code>?</p>
  
  <p>For these variables </p>
  
  <pre><code>$from = '2014-08-15';
  $to = '2014-08-19'
  </code></pre>
  
  <p>I'd like to get <code>[2, 3]</code> as the result of query.</p>
  
  <p>For second query</p>
  
  <pre><code>$from = '2014-08-14';
  $to = '2014-08-19'
  </code></pre>
  
  <p>I'd like to get only  <code>[3]</code> as the result of query, because ObjectID <code>2</code> is booked from <code>13 aug</code> to <code>15 aug</code></p>