title: last year, this year, next year with php DateTime
body: <p>I am trying to create a dropbox that will display the last year, the current year and the next year using the php DateTime object.</p>
  
  <p>In my current code I create three objects and have to call a method on 2 of them. This seems a bit heavy on the resources.</p>
  
  <pre><code>$today = new DateTime();
  $last_year=new DateTime();
  $last_year-&gt;sub(new DateInterval('P1Y'));
  $next_year = new DateTime();
  $next_year-&gt;add(new DateInterval('P1Y'));
  echo date_format($last_year, 'Y').' '.date_format($today, 'Y').' '.date_format($next_year, 'Y');
  </code></pre>
  
  <p>another way I found to only use 1 object is</p>
  
  <pre><code>$today = new DateTime();
  echo date_format($today-&gt;sub(new DateInterval('P1Y')), 'Y').' '.date_format($today-&gt;add(new DateInterval('P1Y')), 'Y').' '.date_format($today-&gt;add(new DateInterval('P1Y')), 'Y');
  </code></pre>
  
  <p>but that will become very confusing.
  Can someone tell me a better way to do this using <code>DateTime()</code>? As I will need something similar for months ?</p>