title: How Do I Search Between a Date Range, Using the ActiveRecord Model?
body: <p>I am new to both Ruby and ActiveRecord. I currently have a need to modify and existing piece of code to add a date range in the select.  The current piece goes like this:</p>
  
  <pre><code>ReportsThirdparty.find(:all, :conditions =&gt; {:site_id=&gt;site_id, :campaign_id=&gt;campaign_id, :size_id=&gt;size_id})
  </code></pre>
  
  <p>Now, I need to add a range, but I am not sure how to do the <code>BETWEEN</code> or <code>&gt;=</code> or <code>&lt;=</code> operators.  I guess what I need is something similar to:</p>
  
  <pre><code>ReportsThirdparty.find(:all, :conditions =&gt; {:site_id=&gt;site_id, :campaign_id=&gt;campaign_id, :size_id=&gt;size_id, :row_date=&gt;"BETWEEN #{start_date} AND #{end_date}")
  </code></pre>
  
  <p>Even if this did work, I know that using interpolation here would leave me subject to SQL injection attacks.</p>