Bug #52480 [Opn->Fbk]: Incorrect difference using DateInterval

From: Date: Thu, 29 Jul 2010 06:27:50 +0000
Subject: Bug #52480 [Opn->Fbk]: Incorrect difference using DateInterval
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152908@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52480&edit=1

 ID:                 52480
 Updated by:         rasmus@php.net
 Reported by:        alex dot joyce at staff dot comcen dot com dot au
 Summary:            Incorrect difference using DateInterval
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Date/time related
 Operating System:   Debian 5.0.3
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

Don't you mean 4 months and 28 days in the expected results?  7-3=4,
29-1=28
And that is exactly what I get on my Debian box with PHP 5.3.3:


php >   $date_start = new DateTime('2010-03-01');
php >   $date_end   = new DateTime('2010-07-29');
php > 
php >   $interval = $date_start->diff($date_end);
php > 
php >   print_r($interval);
DateInterval Object
(
    [y] => 0
    [m] => 4
    [d] => 28
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 150
)

Are you using 5.3.3 built from our sources or are you using a
Debian-packaged 
version?


Previous Comments:
------------------------------------------------------------------------
[2010-07-29 04:49:26] alex dot joyce at staff dot comcen dot com dot au

Description:
------------
Trying to calculate the month difference between two dates accurately.

Test script:
---------------
<?php

  $date_start = new DateTime('2010-03-01');
  $date_end   = new DateTime('2010-07-29');

  $interval = $date_start->diff($date_end);

  print_r($interval);

Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 4
    [d] => 29
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 150
)

Actual result:
--------------
DateInterval Object
(
    [y] => 0
    [m] => 5
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 150
)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52480&edit=1


Thread (28 messages)

« previous php.bugs (#152908) next »