I'm having a rather strange problem using the date function date PHP 5.3 to calculate the difference in days between two dates. Below is my code:
$currentDate = new DateTime(); // (today date is 2012-1-27) $startDate = new DateTime('2012-04-01'); $diff = $startDate->diff($currentDate); $daysBefore = $diff->d; echo $daysBefore;
The above code displays 4 as the value of the $ daysBefore variable.
Why PHP shows the difference of 4 days between the dates of January 27, 2012 and April 1, 2012, when there are still many days between these dates.
Am I doing something wrong?
Bug magnet
source share