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

 ID:                 52480
 User updated by:    alex dot joyce at staff dot comcen dot com dot au
 Reported by:        alex dot joyce at staff dot comcen dot com dot au
 Summary:            Incorrect difference using DateInterval
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Debian 5.0.3
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

Changing the timezone shows a difference.



Australia/Sydney (default): 5 months

UTC: 4 months 28 days


Previous Comments:
------------------------------------------------------------------------
[2010-07-29 09:35:01] degeb...@php.net

With the timezone set to Europe/Copenhagen, I get the same results as
submitter. When set to UTC, I get the same results on Rasmus. This is on
Ubuntu 10.04.



dan...@daniel-laptop:~$ php -v

PHP 5.3.4-dev (cli) (built: Jul 29 2010 09:30:24) 

Copyright (c) 1997-2010 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

------------------------------------------------------------------------
[2010-07-29 09:15:41] ras...@php.net

I don't see why I can't reproduce it then.  Try adding a call to 

date_default_timezone_set() to the top of your script and work in UTC to


eliminate local timezone issues.  



  date_default_timezone_set('UTC');

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

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

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

  print_r($interval);

------------------------------------------------------------------------
[2010-07-29 08:52:20] alex dot joyce at staff dot comcen dot com dot au

28/29, it doesn't matter. I'm only interested in the months.



I've tried:



1) FreeBSD 6, PHP 5.3.2

2) Debian 4, PHP 5.3.2

3) Debian 6, PHP 5.3.2/PHP 5.3.3



I upgraded that last one to submit this bug report, same fault.



All compiled from source.

------------------------------------------------------------------------
[2010-07-29 08:27:50] ras...@php.net

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?

------------------------------------------------------------------------
[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

Reply via email to