title: Finding Last Day of Previous Month in PHP
body: <p>I'm a little unsure why this is not able to find the last day of the previous month.  Every steps seems to be working correctly, except when the final date is created.</p>
  
  <pre><code>&lt;?php
  
  $currentMonth = date('n');
  $currentYear = date('Y');
  
  if($currentMonth == 1) {
      $lastMonth = 12;
      $lastYear = $currentYear - 1;
  }
  else {
      $lastMonth = $currentMonth -1;
      $lastYear = $currentYear;
  }
  
  if($lastMonth &lt; 10) {
      $lastMonth = '0' . $lastMonth;
  }
  
  $lastDayOfMonth = date('t', $lastMonth);
  
  $lastDateOfPreviousMonth = $lastYear . '-' . $lastMonth . '-' . $lastDayOfMonth;
  
  $newLastDateOfMonth = date('F j, Y', strtotime($lastDateOfPreviousMonth));
  
  ?&gt;
  </code></pre>
  
  <p><code>$lastDateOfPreviousMonth</code> is returning 2012-09-30 as expected; however, after trying to convert it to September 30, 2012 - <code>$newLastDateOfMonth</code> is returning October 1, 2012.  Where do I seem to be going wrong?</p>
  
  <p>EDIT:  If using <code>date("t/m/Y", strtotime("last month"));</code> or <code>date('Y-m-d', strtotime('last day of previous month'));</code> will either of these still be viable given 2013-01-01, i.e. will they account for the change in year?</p>