Bug #60960 [NEW]: Wrong number of days.

From: Date: Thu, 02 Feb 2012 19:48:53 +0000
Subject: Bug #60960 [NEW]: Wrong number of days.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-167069@lists.php.net to get a copy of this message
From:             
Operating system: Ubuntu 11.04 64bits
PHP version:      Irrelevant
Package:          Date/time related
Bug Type:         Bug
Bug description:Wrong number of days.

Description:
------------
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:
---------------
<html><head><title>TEST</title></head><body>
<?php
$a = new DateTime('2012-10-19');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
<?php
$a = new DateTime('2012-10-20');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
<?php
$a = new DateTime('2012-10-21');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
</body></html>

Expected result:
----------------
$interval->days:3

$interval->days:2

$interval->days:1

Actual result:
--------------
$interval->days:3

$interval->days:2

$interval->days:0



-- 
Edit bug report at https://bugs.php.net/bug.php?id=60960&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=60960&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=60960&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=60960&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=60960&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60960&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=60960&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=60960&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=60960&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=60960&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=60960&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=60960&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=60960&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=60960&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=60960&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=60960&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60960&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=60960&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=60960&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=60960&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=60960&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=60960&r=mysqlcfg



Thread (11 messages)

« previous php.bugs (#167069) next »