title: Get Start and End Days for a Given Week in PHP
body: <p>I'm trying to get the week range using Sunday as the start date, and a reference date, say <code>$date</code>, but I just can't seem to figure it out.</p>
  
  <p>For example, if I had $date as 2009-05-01, I would get 2009-04-26 and 2009-05-02. 2009-05-10 would yield 2009-05-10 and 2009-05-16. My current code looks like this (I can't remember where I lifted it from, as I forgot to put down the url in my comments):</p>
  
  <pre><code>function x_week_range(&amp;$start_date, &amp;$end_date, $date)
  {
      $start_date = '';
      $end_date = '';
      $week = date('W', strtotime($date));
      $week = $week;
  
      $start_date = $date;
  
      $i = 0;
      while(date('W', strtotime("-$i day")) &gt;= $week) {
          $start_date = date('Y-m-d', strtotime("-$i day"));
          $i++;
      }
  
      list($yr, $mo, $da) = explode('-', $start_date);
  
      $end_date = date('Y-m-d', mktime(0, 0, 0, $mo, $da + 6, $yr));
  }
  </code></pre>
  
  <p>I realized all it did was add 7 days to the current date. How would you do this?</p>