$startDate = new DateTime("2016-06-01");
$endDate = new DateTime("2016-06-30");
$diff = date_diff($startDate,$endDate);
$differenceYear = $diff->format("%y");
$differenceMonth = $diff->format("%m");
$difference = $differenceYear*12 + $differenceMonth;
echo $difference;
As a result, the code above outputs 0. But when I change these two dates to 2016-12-01 and 2016-12-31, the code gives 1 as the output. Why is this happening?
When I check this PHP editor of this code, it gives the correct answer. But when I copied it to my local machine, the answer showed the wrong character. The online editor has US / Pacific as a time zone. My computer has an Asia / Calcutta time zone . Both have the same version of PHP
source
share