开发者

Why does DateTime::diff return 0 days between these dates?

Consider the following test case:

$start = new DateTime("2011-02-25");
$end = new DateTime("2011-03-25");

$interval = $end->diff($start);


echo "INTERVAL = ".$interval->format("%d");  // Should give me the 
                                             // interval in days, right?
echo "START = ".$start->format("Y-m-d");
echo "END = ".$end->form开发者_StackOverflow社区at("Y-m-d");

The result is:

INTERVAL = 0  <---------- WTF????
START = 2011-02-25
END = 2011-03-25

diff() seems to claim that the period between February 25th, 2011 and March 25, 2011 is 0 days!

I must be overlooking something. But what?


you need to use format code 'a'. d is the number of days in the diff, not the net number of days. in the dateinterval object, days is the corresponding field. in your example, you will see m = 1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜