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?
function termLength($dateFrom, $dateTo) {
$dateFrom = (($dateFrom instanceof DateTime) ? $dateFrom : new DateTime($dateFrom));
$dateTo = (($dateTo instanceof DateTime) ? $dateTo : new DateTime($dateTo));
$difference = $dateTo->format('U') - $dateFrom->format('U');
return floor($difference / (60 * 60 * 24));
}
echo termLength('2013-03-28', '2013-04-01');
// output: 3
// it should be: 4
Can you help me, please? Thanks, J.
Try this: