From:
Operating system: Windows NT ABC-223D173EDE7 5.1 b
PHP version: 5.3.6
Package: *General Issues
Bug Type: Bug
Bug description:Unexpected output for DATETIME:diff()
Description:
------------
---
I've followed all the reported bugs & forums. However, still not got any
solution for this. Please help me to fix this bug.
---
<?php
$datetime1 = new DateTime('2011-05-01');
$datetime2 = new DateTime('2011-05-07');
$interval = $datetime1->diff($datetime2); print_r($interval);
echo $interval->format('%R%a days');
?>
O/P: DateInterval Object ( [y] => 0 [m] => 0 [d] => 6 [h] => 0 [i] => 0 [s]
=> 0 [invert] => 0 [days] => 6015 ) +6015 days
The o/p always gives the same unexpected result for any dates. i.e, +6015
Test script:
---------------
<?php
$datetime1 = new DateTime('2011-05-01');
$datetime2 = new DateTime('2011-05-07');
$interval = $datetime1->diff($datetime2); print_r($interval);
echo $interval->format('%R%a days');
?>
Expected result:
----------------
O/P: DateInterval Object ( [y] => 0 [m] => 0 [d] => 6 [h] => 0 [i] => 0 [s]
=> 0 [invert] => 0 [days] => 6015 ) +6015 days
Actual result:
--------------
6 days
--
Edit bug report at http://bugs.php.net/bug.php?id=54685&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54685&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54685&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54685&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54685&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54685&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54685&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54685&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54685&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54685&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54685&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54685&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54685&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54685&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54685&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54685&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54685&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54685&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54685&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54685&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54685&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54685&r=mysqlcfg