|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60960 Wrong number of days.
Submitted: 2012-02-02 19:48 UTC Modified: 2017-10-24 07:58 UTC
Avg. Score:3.8 ± 1.5
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: robertosuursoo at yahoo dot com dot br Assigned:
Status: Open Package: Date/time related
PHP Version: Irrelevant OS: Ubuntu 11.04 64bits
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
31 - 21 = ?
Subscribe to this entry?

 [2012-02-02 19:48 UTC] robertosuursoo at yahoo dot com dot br
The diff function is calculating the wrong number of days.

PHP 5.3.5-1ubuntu7.4 with Suhosin-Patch (cli) (built: Dec 13 2011 18:30:11) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Test script:
$a = new DateTime('2012-10-19');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
$a = new DateTime('2012-10-20');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
$a = new DateTime('2012-10-21');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);

Expected result:



Actual result:




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-02 20:15 UTC] carloschilazo at gmail dot com
I couldnt reproduce the problem, I get a result of 1 on:

$a = new DateTime('2012-10-21');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);

Tested Ubuntu 11 64 bits also
 [2012-02-02 21:42 UTC] anon at anon dot anon
Obviously some wretched daylight savings issue. Call:
It's the only way to make any programming language's date handling sane.
 [2012-02-02 22:04 UTC]
Unable to reproduce here as well with PHP 5.3.10. Which timezone are you using? 
Most likely DST-related.
 [2012-02-03 00:50 UTC]
-Status: Open +Status: Not a bug
 [2012-02-03 00:50 UTC]
Yep, this happens with the Brazil/East time zone, so it's just crossing a DST 
boundary: if you look at $interval->h on the last interval, it's 23 hours from 
midnight on the 21st to midnight on the 22nd and therefore not a full day.
 [2012-02-03 13:43 UTC] robertosuursoo at yahoo dot com dot br
Thanks a lot!
 [2012-02-03 14:10 UTC] robertosuursoo at yahoo dot com dot br
The function call worked perfectly and solved the problem!


Thank you very much!
 [2012-02-03 14:12 UTC]
-Status: Not a bug +Status: Assigned -Assigned To: +Assigned To: derick
 [2012-02-03 14:12 UTC]
This is a bug, it should show 1.
 [2017-10-24 07:58 UTC]
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 01 02:01:23 2021 UTC