Why in this code at the output is the result?
$datetime1 = date_create('2014-03-01'); $datetime2 = date_create('2014-03-31'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%Y %m %d'); ---- 00 1 2 ----
Where did 2 days come from?
change the starting date a bit:
$datetime1 = date_create('2014-03-02'); $datetime2 = date_create('2014-03-31'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%Y %m %d'); ---- 00 0 29 ----
only +1 day have been added, and not 1 month and 2 days, but 0 month and 29 days ...
00 0 30
. And if you change the timezone, for example, to 'America / New_York', the above code begins to be considered correctly. As a solution, get the number of days $ interval-> format ('% a'); and already process the received value independently - vanchester