|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65003 Wrong date diff
Submitted: 2013-06-10 12:08 UTC Modified: -
Avg. Score:4.4 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: hcy321+php at yandex dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.4.16 OS: OSX
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: hcy321+php at yandex dot com
New email:
PHP Version: OS:


 [2013-06-10 12:08 UTC] hcy321+php at yandex dot com
DateTime::diff return wrong result for first day of month.
Tested on PHP Version 5.4.10 \ 5.4.15

Test script:

$datetime1 = new DateTime('13-03-01');
$datetime2 = new DateTime('13-04-01');

$datetime3 = new DateTime('13-03-02');
$datetime4 = new DateTime('13-04-02');

$interval = $datetime2->diff($datetime1);
echo $interval->format('%m month, %d days'), '<br>'; //1 month, 3 days

$interval = $datetime4->diff($datetime3);
echo $interval->format('%m month, %d days'); //1 month, 0 days

Expected result:
1 month, 0 days
1 month, 0 days

Actual result:
1 month, 3 days
1 month, 0 days


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-11 12:03 UTC] ppasindud at gmail dot com
I had a similar error and check the src in intervel.c timelib_diff the date is changed to 
local or gmt



rt->d = two->d - one->d;

and makes it 1 month and 3 days 
could it be solved by only running timelib_apply_localtime if date zones are
different or else can put some other conditions to to prevent this, any other 
way to solve this, bug is for php 5.4 but exists in newer versions too.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Mar 07 09:01:23 2021 UTC