|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-02-19 13:56 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 05:00:01 2025 UTC |
Temporary workaround is to add $datetime->sub(new DateInterval("P0D")); after $datetime->sub(new DateInterval("P2D"));