|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52798 dateTime => function diff => days KO
Submitted: 2010-09-08 17:19 UTC Modified: 2013-02-18 00:34 UTC
Avg. Score:4.5 ± 0.8
Reproduced:9 of 10 (90.0%)
Same Version:6 (66.7%)
Same OS:8 (88.9%)
From: ebinachon at pierre-vacances dot fr Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.3.3 OS: windows xp
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: ebinachon at pierre-vacances dot fr
New email:
PHP Version: OS:


 [2010-09-08 17:19 UTC] ebinachon at pierre-vacances dot fr
I have a probleme with the function diff of dateTime.
When i do a test, the "days" result is always : 6015.
All the other informations ( Y, m, d, ... ) are correct.

Have-you an idea ?

Test script:
Exemple :
$date1 = new DateTime('2010-01-01');
$date2 = new DateTime('2010-03-13');
$interval = $date2->diff($date1);


Result :
object(DateInterval)#174 (8) {
  ["y"] => int(0)
  ["m"] => int(2)
  ["d"] => int(12)
  ["h"] => int(0)
  ["i"] => int(0)
  ["s"] => int(0)
  ["invert"] => int(0)
  ["days"] => int(6015)

Expected result:
days => 71

Actual result:
days => 6015


52798 (last revision 2010-09-23 06:22 UTC by akabirov at rambler dot ru)
date_diff (last revision 2010-09-08 16:03 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-08 17:36 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: derick
 [2010-09-08 17:36 UTC]
I can reproduce only on Windows. The exactly value varies (seems to be garbage memory).
 [2010-09-08 18:03 UTC]
The following patch has been added/updated:

Patch Name: date_diff
Revision:   1283961826
 [2010-09-08 18:12 UTC]
The problem was the call to floor().

The compiler gave a warning:
"d:\users\cataphract\documents\php-trunk\ext\date\lib\interval.c(57) : warning C4013: 'floor' undefined; assuming extern returning int"

The assumption is wrong, because it calls

double  __cdecl floor(_In_ double _X);

Which takes and returns a larger type.

I removed the call to floor, which is unnecessary since it's an integer division.

I also changed the call to abs to a call to llabs to avoid the conversion from long long to int and then to long long again.
 [2011-01-30 10:49 UTC]
-Status: Verified +Status: Feedback
 [2011-01-30 10:49 UTC]
Please try using this snapshot:
For Windows:

Works fine for me with current SVN 5.3 HEAD.
 [2011-01-30 11:22 UTC]
Also, please try vc9 build.
 [2012-02-24 17:51 UTC] kissifrot at gmail dot com
Reproduced on PHP Win32 5.3.10 VC6, but not the VC9.
 [2013-02-18 00:34 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 "Open". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 19:01:25 2021 UTC