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

 ID:                 51184
 Comment by:         alabi10 at yahoo dot com
 Reported by:        s...@php.net
 Summary:            DateInterval has incorrect days property on windows
 Status:             Wont fix
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows
 PHP Version:        5.3.2
 Assigned To:        pajoye
 Block user comment: N
 Private report:     N

 New Comment:

The fix submitted by fbast...@yahoo.com on 2011-10-16 16:13 UTC solved the 
problem 
for me on Windows 7 running WAMP on localhost and php 5.3.0


Previous Comments:
------------------------------------------------------------------------
[2011-11-12 15:08:05] iskeen at barebrush dot com

I am surprised that the number of days between two dates problem is not made 
clear right up front in the documentation. It took me 3 hours to find this page 
and I was trying all different things to make it work. I suspected a problem 
when the three different sets of dates I was using all came out with the same 
answer, but when I finally used %a and they all came out with 6015, I knew, 
finally, that there is a problem. The fact of the problem should be made very 
clear right up front.

------------------------------------------------------------------------
[2011-10-16 16:13:05] fbastage at yahoo dot com

Here's a reasonably close substitute  (run result through abs() if you don't 
want potentially negative numbers):

// $dt1 and $dt2 can be any valid date string that DateTime accepts
// the time zone shouldn't affect anything (since $dt1 and $dt2 use same zone),
// but you can override the default
function daysdiff($dt1, $dt2, $timeZone = 'America/Chicago') {
  $tZone = new DateTimeZone($timeZone);
  
  $dt1 = new DateTime($dt1, $tZone);
  $dt2 = new DateTime($dt2, $tZone);  
  
  // use the DateTime datediff function IF we have a non-buggy version
  // there is a bug in many Windows implementations that diff() always returns
  // 6015  
  if( $dt1->diff($dt1)->format("%a") != 6015 ) {
    return $dt1->diff($dt2)->format("%a");
  }
  
  // else let's use our own method

  $y1 = $dt1->format('Y');  
  $y2 = $dt2->format('Y');
  $z1 = $dt1->format('z');
  $z2 = $dt2->format('z');
  
  $diff = intval($y1 * 365.2425 + $z1) - intval($y2 * 365.2425 + $z2);

  return $diff;

}

------------------------------------------------------------------------
[2011-09-05 18:06:18] a at a dot com

Not solved with 5.3.5 on Windows.

------------------------------------------------------------------------
[2011-07-04 10:55:22] tux at penguinfriends dot org

Not solved with 5.3.5 on Windows...

------------------------------------------------------------------------
[2011-01-03 11:02:59] paj...@php.net

@toto at hotmail dot com

Nothing changed so yes, use VC9 builds instead for now.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=51184


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

Reply via email to