title: First and Last day of the previous week with Postgresql
body: <p>I'm trying to find a way to query for the first day and last day of the previous week with postgresql. </p>
  
  <p>I've found the answer for both mysql ,sql server and other but couldn't find it for PSQL.</p>
  
  <p>I've been trying using current_date and intervals <code>1 week</code> or <code>- integer '7'</code> ( <code>BETWEEN current_date - INTERVAL '1 weeks' and current_date</code> ) but it just gives me 1 week back from the current day and not the first or last day in store for the previous week.</p>
  
  <p>I'm looking for something dynamic : The first day of the previous week could be tuesday and the last day thursday it's not always monday and friday depends what has been stored for the previous week.</p>
  
  <p>I need to be able to retreive a result for the 1st day of the previous week aswell as the last day so it's going to be 2 queries i believe.</p>
  
  <p>edit :  <strong>My main issue is that most answer around the same problem use current_date / now() and subtract a fix number of days to retrieve the first day of the previous week. But the query should be dynamic it won't be done on the same day every week - so the subtraction of days will be different depending on which day the query is performed -  AND the first day of previous week that i have in store isn't always monday and last day isn't always friday. Sometimes i'll only have 3 days worth of data for a week so the first day will be tuesday and last day thursday and i wouldn't want to return NULL for monday and Null for friday</strong> </p>
  
  <p>edit 2 :</p>
  
  <p>dummy data looks like that :</p>
  
  <pre><code>id |  date         
   1    monday(w1)      
   2    tuesday(w1)
   3    wednesday(w1)
   4    thursday(w1)
   5    friday(w1)
   6    tuesday(w2)
   7    wednesday(w2)
   8    friday(w2)
   9    monday(w3)
  10    tuesday(w3)
      --query ran here--   
  </code></pre>
  
  <p>Obviously my dates are stored as actual date format ( 2019-10-24 ) but on the date of the query ( hypnotically wednesday ) i'd want the first item of the previous week to be id 6  and the last item to be id 8</p>