title: MySQL query DATE comparison
body: <p>I have a problem with my query. Its giving me the correct result for some cases and for some it does not, so if anyone could tell me what to change it'd be amazing cause I'm stuck with it for some time now. Here is my table data:</p>
  
  <p>Table reservation_logs:</p>
  
  <pre><code>log_id      int(15) auto_increment   Primary   Unique  
  room_log    int(10)         
  dt_from     date                
  dt_until    date            
  </code></pre>
  
  <p>Table apartments:</p>
  
  <pre><code>apartman_id     int(10) auto_increment   Primary   Unique   
  apartman_name   int(10)
  </code></pre>
  
  <p>My php code for date:</p>
  
  <pre><code>$date_from = 'text input date';
  $date_until = 'text input date';
  
  $myquery = ("SELECT * FROM reservation_logs WHERE room_log = '$apartman_id'  
  AND(((dt_from &gt;= '$date_from' AND dt_from &lt;= '$date_until') 
  AND (dt_until &gt;= '$date_until' OR dt_until &lt;= '$date_until')))");
  </code></pre>
  
  <p>Now I input some dates I should get correct <code>apartman_id</code>, if its busy or not. Here is case when this is working: when <code>$date_from</code> equals 1st day in the month and <code>$date_until</code> equals last day in a month. But for example if I choose dates <code>$date_from</code> equals 16th of the month and <code>$date_until</code> equals 17th of the month I get incorrect results if room is busy from 15th of the month until 19th lets say. I hope I didn't complicate too much I just wanted for more people to get idea behind this.</p>