title: How can I find out the date of the day before a date?
body: <p>I have a system that compares fiscal year up to the current date to the same date range of the year before. You can adjust the year and month to look at and it always compares the same date range to the year previous. I have it set so if the current day is leap day it compares to the 28th of last year, and if last year was leap year and today is feb 28th it compares to last year up to 29th. if you look at a month other than the current month it shows up to the last day of that month, otherwise up to current date.</p>
  
  <p>OK that works fine right now, but now my employers don't want it to be up to the current date they want it to go up to yesterdays date. How can I do that, my main concerns are what if today is the 1st of the month, or what if today is the first day of the fiscal year.</p>
  
  <p>Here is the code I have now:</p>
  
  <pre><code>function create_YTD_XML()
  {
      global $month;
      global $year;
  
      $last_year = $year - 1;
  
      if($year == date('Y') &amp;&amp; $month == date('m'))
      {
          $this_day = date('d');
      }
      else
      {
          $this_day = date('t', mktime(0, 0, 0, $month, 1, $year)); // LAST DAY OF MONTH
      }
  
      if(is_leap_year($year) &amp;&amp; $this_day == 29)
      {
          $last_day = 28;
      }
      else if(is_leap_year($last_year) &amp;&amp; $this_day == 28)
      {
          $last_day = 29;
      }
      else
      {
          $last_day = $this_day;
      }
  
      if($month &gt;= 2)
      {
          $this_year_start = $year;
          $last_year_start = $last_year;
      }
      else
      {
          $this_year_start = $year - 1;
          $last_year_start = $last_year - 1;
      }
  
      $this_ytd_start = $this_year_start.'-02-01';
      $last_ytd_start = $last_year_start.'-02-01';
  
      $this_ytd_end = $year.'-'.str_pad($month, 2, "0", STR_PAD_LEFT).'-'.$this_day;
      $last_ytd_end = $last_year.'-'.str_pad($month, 2, "0", STR_PAD_LEFT).'-'.$last_day;
  
  
  }
  </code></pre>
  
  <p>What would be the best solution?</p>
  
  <p>Thanks!</p>