|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74529 DateTime::diff seems to ignore $absolute = true
Submitted: 2017-05-02 11:03 UTC Modified: 2017-05-14 04:22 UTC
From: hrovira at seocom dot es Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 7.1.4 OS: Ubuntu 16.04.2 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: hrovira at seocom dot es
New email:
PHP Version: OS:


 [2017-05-02 11:03 UTC] hrovira at seocom dot es
DateTime::diff generates different DateInterval results depending on the order, even though $absolute param is set to true. date1->diff(date2, true) is different than date2->diff(date1, true). Please, see test script.

Test script:

$date1 = date_create("2014-11-01 00:00:00");
$date2 = date_create("2017-05-01 04:00:00");

$diff1 = $date2->diff($date1, true);
$diff2 = $date1->diff($date2, true);

echo $diff1->m .' months, '.$diff1->d. ' days';
// outputs: 6 months, 0 days
echo $diff2->m .' months, '.$diff2->d. ' days';
// outputs: 5 months, 30 days

Expected result:
6 months, 0 days
5 months, 30 days

Actual result:
6 months, 0 days
6 months, 0 days


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-02 11:04 UTC] hrovira at seocom dot es
Obviously, expected and actual results are switched :(
 [2017-05-02 12:12 UTC] andrew dot nester dot dev at gmail dot com
thanks for reporting this issue!
I tried to reproduce it on latest 7.1 build (7.1.6-dev) - working good.
but anyway I decided to add test to prove that it works as expected (see my PR)
 [2017-05-02 12:34 UTC]
Andrew, it might look fixed for you because you have a different timezone with different DST rules configured.
 [2017-05-02 14:10 UTC]
-Package: SPL related +Package: Date/time related
 [2017-05-02 20:06 UTC] andrew dot nester dot dev at gmail dot com
Thanks Derick!
gonna rework my pull request
 [2017-05-03 12:17 UTC] andrew dot nester dot dev at gmail dot com
I've just updated my PR to fix the issue.
 [2017-05-06 18:56 UTC]
-Status: Open +Status: Feedback
 [2017-05-06 18:56 UTC]
To me this looks like a duplicate of depending on which way the diff starts…
 [2017-05-14 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 18:03:38 2021 UTC