title: php codeigniter getting number of months from 2 different dates
body: <p>I am trying to get the number of months from two different dates. 
  I am using codeigniter php, and I have seen in alot of places that the code I am using should work, but I am getting a error.</p>
  
  <pre><code>public function check($token){
  if ($this-&gt;input-&gt;is_ajax_request()){
      $id = $this-&gt;myajax-&gt;getUserByAuth($token);
      if ($id){
          $this-&gt;load-&gt;model('user_profile');
          $result = $this-&gt;user_profile-&gt;check($id);
  
          $this-&gt;load-&gt;model('riskrating');
          //$this-&gt;riskrating-&gt;getRiskrateOfuser($id);
          $riskCategory ='4';
          $result['riskCategory']  = $riskCategory;
  
  
          $date1 = new DateTime($result['insertdate']);
          $date2 = new DateTime('now');
          $diff = $date1-&gt;diff($date2);
          $month = $diff-&gt;format('%m');
          if ($month &gt; 6){
           return  $result['month'] = 'invalid';
          }else{
             return $result['month'] = 'valid';
          }
  
          $this-&gt;output-&gt;set_content_type('application/json');
          $this-&gt;output-&gt;set_output(json_encode($result));
      } else {
          $this-&gt;output-&gt;set_status_header('401', 'Could not identify the user!');
      }
  } else {
      $this-&gt;output-&gt;set_status_header('400', 'Request not understood as an Ajax request!');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The <code>$date1</code> has a value of '2016-08-19'.
  is it because that they are not different months? I thought if they are the same month it should just return zero.
  But how much I can see from debugging the error is in this line
  <code>$diff = $date1-&gt;diff($date2);</code></p>