ID: 51090
Updated by: [email protected]
Reported By: aj at dl10design dot co dot uk
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: Centos 5
PHP Version: 5.3.1
New Comment:
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same.
Thank you for your interest in PHP.
See bug #50916 (and try search before you submit anything..)
Previous Comments:
------------------------------------------------------------------------
[2010-02-19 13:57:43] aj at dl10design dot co dot uk
Temporary workaround is to add
$datetime->sub(new DateInterval("P0D"));
after
$datetime->sub(new DateInterval("P2D"));
------------------------------------------------------------------------
[2010-02-19 13:56:13] aj at dl10design dot co dot uk
Description:
------------
When using set time after modifying the date by using sub, the sub is
re-applied as well.
Reproduce code:
---------------
date_default_timezone_set('Europe/London');
$datetime = new DateTime('2010-02-19 14:52:10');
$datetime->sub(new DateInterval("P2D"));
// Date should now be 2010-02-17
echo $datetime->format("Y-m-d H:i:s") . "<br />";
$datetime->setTime(15,0,0);
// Date and time should now be 2010-02-17 15:00:00
// BUT it is 2010-02-15 15:00:00
echo $datetime->format("Y-m-d H:i:s");
Expected result:
----------------
Only the time should have be changed
Actual result:
--------------
Day and date are changed.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51090&edit=1