$now = new DateTime('now');
$tomorrow = new DateTime('tomorrow');
$next_year = new DateTime('+1 year');
echo "<pre>";
print_r($now->diff($tomorrow));
print_r($now->diff($next_year));
echo "</pre>";
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 0
[h] => 10
[i] => 17
[s] => 14
[invert] => 0
[days] => 6015
)
DateInterval Object
(
[y] => 1
[m] => 0
[d] => 0
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 6015
)
any ideas why 'days' shows 6015? why won't it show the total number of days? 1 year difference means nothing to me, since months have vary开发者_StackOverflow社区ing number of days.
A more appropriate bug report to follow would be #51184 which focuses on the problem of Windows reporting 6015 days (non-Windows appears OK).
No feedback has been given as yet with regards to whether the fix for #49778 (which deals with a different issue) affects this or if the problem persists. If anyone here could take a look and provide some feedback, that would be very kind of you.
Please upgrade to the latest php. This error only occurs on php 5.3 VC6.
$now = new DateTime('now');
should be
$now = new DateTime(''2010-01-01 00:00:00'');
more in the manual http://nl3.php.net/manual/en/datetime.diff.php
Ok, looks like http://bugs.php.net/bug.php?id=49778 is the issue here.
its a bug http://bugs.php.net/bug.php?id=49778
Thank you for your bug report.
Days is indeed not set when creating a DateInterval using the constructor. A complication with this is that it is impossible to determine the number of days when months or years are specified, since these vary in length. It is possible to fill in the days field in some cases and leave it 0 in others. In any case, it should be documented that the days field is not always available.
精彩评论