title: Getting data from mysql between two dates for a joomla project
body: <p>I must modify a simple project to display some values in a different way. </p>
  
  <p>I got a MySQL database, in which are stored reservations.</p>
  
  <p>I want to get all data from  a reservation, selecting the room and the period.</p>
  
  <p>that's my query:</p>
  
  <pre><code>function getReservation($idroom,$date){
      $db=JFactory::getDbo();
      $query=$db-&gt;getQuery(true);
      $datecheck=$date-&gt;format('%Y-%m-%d');
  
      $query
           -&gt;select($db-&gt;quoteName(array('idroom','status','idguests','nguests','value_paid','value_pending','value_full','valid_from','valid_to','today','extra_ids','nchilds')))
           -&gt;from($db-&gt;quoteName('#__bookitbooking'))
           -&gt;where($db-&gt;quoteName('idroom')."=".$idroom)
           -&gt;and ( $db-&gt;quoteValue($datecheck) . "BETWEEN" . $db-&gt;quoteName('valid_from') . "AND" . $db-&gt;quoteName('valid_to'));
      $db-&gt;setQuery($query);
  
      $res = $db-&gt;loadObjectList();
      return $res;
  }
  </code></pre>
  
  <p>But  the <code>and</code> clause  seems to not have effect, in fact when I get the count of reservation stored from the query, I got all that matches with the <code>$idroom</code> value.</p>
  
  <p>With that function I want to know if for a particular date exists a reservation, and if it exists I want to get all the parameters.</p>
  
  <p>Where's my mistake?</p>
  
  <p>Obviously I can obtain at maximum just one reservation object.</p>