|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74524 Date diff is bad calculated, in same time zone
Submitted: 2017-05-01 20:59 UTC Modified: 2021-04-06 19:54 UTC
Avg. Score:3.3 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kalita dot michal at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.4 OS: Linux
Private report: No CVE-ID: None
 [2017-05-01 20:59 UTC] kalita dot michal at gmail dot com
Calculated diff is 7 months, 14 days and -1 hour.

It doen't make sense, why it is not 7 months, 13 days and 23 hours.

This bug is in versions 5.4.45, 5.6.30, 7 and newest. (

Test script:
$a = new DateTime("2017-11-17 22:05:26.000000");
$b = new DateTime("2017-04-03 22:29:15.079459");

$diff = $a->diff($b);

return $diff->h;

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-02 12:22 UTC] andrew dot nester dot dev at gmail dot com
thanks for reporting the issue!
I've been trying to reproduce it on latest PHP7.1 version (7.1.6-dev) and seems it's fixed already.
Anyway, I've added test to check that it works (see my PR)
 [2017-05-02 12:33 UTC]
Andrew, it might look fixed for you because you have a different timezone with different DST rules configured.
 [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 07:18 UTC] andrew dot nester dot dev at gmail dot com
Just added reworked pull request to this issue. Here is the link
 [2017-05-06 19:02 UTC]
This is a DST issue as can be seen in

The default Timezone of is Europe/Amsterdam which has DST and therefore has the issue!
 [2017-10-30 11:26 UTC] onda204 at gmail dot com
I detected the following issue that may have to do with present Bug.
Using diff with dates that are on range of summer / winter time change, the function diff on element $interval->h gives result -1

Tested width date interval:
15.00 H

14.00 H

Portuguese regional settings
 [2017-12-01 16:46 UTC] miloslav dot hula at gmail dot com
probably another example of bug:

In the Europe/Prague timezone, there was a 1 hour switch back on 29th Oct 2017 from 03:00 to 02:00 (from CEST to CET).

When run on with EOL versions checked, you can notice that behaviour has been correct in 5.3.0-5.4.23, 5.5.0-5.5.7. In the PHP5 5.4.24 and 5.5.8 change log is fixed bug #66060 (
 [2020-10-22 08:54 UTC] steve dot caillault at gmail dot com
I a similar problem with the PHP version 7.4.7 :

$currentDateString = '2020-10-21 22:22:59';
$targetDateString = '2020-10-25 21:30:00';

$timezone = new \DateTimeZone('Europe/Paris');
$currentDateTime = new \DateTime($currentDateString, $timezone);
$targetDateTime = new \DateTime($targetDateString, $timezone);

$dateInterval = $currentDateTime->diff($targetDateTime, TRUE);

echo $dateInterval->h;

$dateInterval->h value is -1, while the value should be 23.

I have the problem on Windows and UNIX.
 [2021-04-06 19:54 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-06 19:54 UTC]
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 8.1.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC