title: how to retrieve results for past n days using postgresql
body: <p>I'm new to postgres  </p>
  
  <p><strong>What I'm trying to do:</strong>
  Get results across previous <code>n</code> days everytime I run the query on a given day without manually updating the start and end dates.</p>
  
  <p><strong>example query:</strong><br>
  If I were running the query today (June 23rd,2019)<br>
  My query to retrieve results for the past 8 days would look like</p>
  
  <pre><code>select count(*),state,DATE(date)
  from animal_shelter
  where date=&gt;'2019-06-15' and date &lt;='2019-06-22'
  group by state,DATE(date);
  </code></pre>
  
  <p>but this requires manual intervention where I'm updating two dates every single time. </p>
  
  <p>I found that there's </p>
  
  <pre><code>now()::date - interval '8 days'
  </code></pre>
  
  <p>which can be used but I didn't understand how to modify use it with the between condition. </p>
  
  <p><em>Possible solution</em></p>
  
  <pre><code>select count(*),state,DATE(date)
  from animal_shelter
  where date=&gt; ( now()::date - interval '8 days') 
  group by state,DATE(date);
  </code></pre>
  
  <p>Is this right, and can I be assured that it picks exactly the 8 past days worth of data not including today?</p>
  
  <p>Please help me accomplish my goal.</p>