|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-05-20 18:36 UTC] kai dot xu at achievers dot com
-PHP Version: 5.4.28
+PHP Version: 5.4.27
[2014-05-20 18:36 UTC] kai dot xu at achievers dot com
[2014-05-24 15:25 UTC] sea128 at post dot cz
[2017-03-19 11:29 UTC] heiglandreas@php.net
-Status: Open
+Status: Duplicate
[2017-03-19 11:29 UTC] heiglandreas@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
Description: ------------ When adding a DateInterval to a DateTime object, it adds unexpected amounts of seconds. For the following time frames, adding DateInterval doesn't work correctly (my PHP version 5.4.27) // PT1M – adding 1 minute. Expected timestamp differential : 60 seconds 1414907940 - 1414911539 ( 2014-11-02 05:59:00 - 2014-11-02 06:58:59 ) test script result: -3540 1414911540 - 1414911599 ( 2014-11-02 06:59:00 - 2014-11-02 06:59:59 ) test script result: -7140 1446357540 - 1446361139 ( 2015-11-01 05:59:00 - 2015-11-01 06:58:59 ) test script result: -3540 1446361140 - 1446361199 ( 2015-11-01 06:59:00 - 2015-11-01 06:59:59 ) test script result: -7140 ------------------------------------------------------------------------------- // PT1H - adding 1 hour. Expected timestamp differential : 3600 seconds 1414904400 - 1414907999 ( 2014-11-02 05:00:00 - 2014-11-02 05:59:59 ) test script result: 0 1414908000 - 1414911599 ( 2014-11-02 06:00:00 - 2014-11-02 06:59:59 ) test script result: -3600 1446354000 - 1446357599 ( 2015-11-01 05:00:00 - 2015-11-01 05:59:59 ) test script result: 0 1446357600 - 1446361199 ( 2015-11-01 06:00:00 - 2015-11-01 06:59:59 ) test script result: -3600 ------------------------------------------------------------------------------- // P1D - adding 1 day. Expected timestamp differential : 86400 seconds 1394265600 - 1394348399 ( 2014-03-08 08:00:00 - 2014-03-09 06:59:59 ) test script result: 82800 1414821600 - 1414907999 ( 2014-11-01 06:00:00 - 2014-11-02 05:59:59 ) test script result: 90000 1425715200 - 1425797999 ( 2015-03-07 08:00:00 - 2015-03-08 06:59:59 ) test script result: 82800 1446271200 - 1446357599 ( 2015-10-31 06:00:00 - 2015-11-01 05:59:59 ) test script result: 90000 ------------------------------------------------------------------------------- Test script: --------------- // e.g. adding 1 minute to a DateTime object. The difference should be 60 but it returns -3560. $ts = 1414907940; $d = date('Y-m-d H:i:s', $ts); $dt = new DateTime($d); $di = new DateInterval('PT1M'); $dt->add($di); echo ($dt->getTimestamp() - $ts); // expecting 60 Expected result: ---------------- add the correct minute/hour/day to a DateTime object for any DateTime object Actual result: -------------- For some time frames, it sometimes adds more, sometimes adds less number of seconds to a Datetime object. (see description)