title: php - find date for same day of week for last year
body: <p>So, in PHP i'm trying to return a date value for last year based on the same day of week.
  EX: (Monday) 2011-12-19 inputted should return (Monday) 2010-12-20.</p>
  
  <p>I was just doing it simply by -364 but then that was failing on leap years. I came across another function :</p>
  
  <pre><code>$newDate = $_POST['date'];
  $newDate = strtotime($newDate);
  $oldDate = strtotime('-1 year',$newDate);
  
  $newDayOfWeek = date('w',$oldDate);
  $oldDayOfWeek = date('w',$newDate);
  $dayDiff = $oldDayOfWeek-$newDayOfWeek;
  
  $oldDate = strtotime("$dayDiff days",$oldDate);
  
  echo 'LAST YEAR DAY OF WEEK DATE = ' . date('Ymd', $oldDate);
  </code></pre>
  
  <p>however, that is failing when you try to input a Sunday date, as it does a 0 (sunday) minus 6 (saturday of last year date), and returns with a value T-6. IE inputting 2011-12-25 gets you 2010-12-19 instead of 2011-12-26.</p>
  
  <p>I'm kind of stumped to find a good solution in php that will work for leap years and obviously all days of the week.</p>
  
  <p>Any suggestions?</p>
  
  <p>Thanks!</p>