title: How do I do this? Model.where("created_at >= #{Time.now - 5.days}")
body: <p>This has been bugging me for a while...</p>
  
  <p>How can I <em>string interpolate</em> a <code>datetime</code> in Rails ActiveRecord queries?</p>
  
  <pre><code># Works, but supeh ugleh:
  Model.where("created_at &gt;= ?", Time.now - 5.days)
  
  # How do I do this?
  Model.where("created_at &gt;= #{Time.now - 5.days}")
  # As is, it produces the following error message:
  # ActiveRecord::StatementInvalid: PG::Error: ERROR:  syntax error at or near ...
  </code></pre>
  
  <p>The reason I care is for code readability:</p>
  
  <pre><code># I like this better:
  Model.where("created_at &gt;= #{Time.now - 5.days} OR" + \
              "updated_at &gt;= #{Time.now - 3.days}")
  
  # than this:
  Model.where("created_at &gt;= ? OR updated_at &gt;= ?", Time.now - 5.days, Time.now - 3.days)
  </code></pre>