日期之间的PHP DateTime差异问题

时间:2014-01-07 05:34:18

标签: php

$start = new DateTime('2014-01-07', new DateTimeZone('UTC'));
$end = clone $start;
$start->sub(new DateInterval('P1M')); // substract one month

echo $start->format('Y-m-d').' - '.$end->format('Y-m-d');
// 2013-12-07 - 2014-01-07 - seems correct, let's get number of days...

print_r($end->diff($start));
// DateInterval Object ( [y] => 0 [m] => 2 [d] => 0 [h] => 0 [i] => 0 [s] => 0 [invert] => 1 [days] => 61 )

61天???这里发生了什么?

1 个答案:

答案 0 :(得分:-1)

试试这个,

$diff=date_diff($date1,$date2);