ID: 51090 Comment by: aj at dl10design dot co dot uk Reported By: aj at dl10design dot co dot uk Status: Open Bug Type: Date/time related Operating System: Centos 5 PHP Version: 5.3.1 New Comment:
Temporary workaround is to add $datetime->sub(new DateInterval("P0D")); after $datetime->sub(new DateInterval("P2D")); Previous Comments: ------------------------------------------------------------------------ [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