title: PHP - Calculate days between two dates - not working in March and April 2013
body: <p>I have problem with my PHP function. It was working until now, when I need to calculate number of days (or more precisely nights) between date 2013-03-28 and 2013-04-01. The result should be 4 (03/28 to 03/29, 03/29 to 03/30, 03/30 to 03/31 and 03/31 to 04/01) and my function returns 3. (When I use 2012-03-28 and 2012-04-01 instead of the same dates in 2013, it works correctly). Can you help me please?</p>
  
  <pre><code>function termLength($dateFrom, $dateTo) {
    $dateFrom = (($dateFrom instanceof DateTime) ? $dateFrom : new DateTime($dateFrom));
    $dateTo = (($dateTo instanceof DateTime) ? $dateTo : new DateTime($dateTo));
  
    $difference = $dateTo-&gt;format('U') - $dateFrom-&gt;format('U');
    return floor($difference / (60 * 60 * 24));
  }
  
  echo termLength('2013-03-28', '2013-04-01');
  
  // output: 3
  // it should be: 4
  </code></pre>
  
  <p>Can you help me, please? Thanks, J.</p>