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

 ID:                 51184
 Comment by:         fbastage 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:

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;

}


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2011-01-03 10:42:41] toto at hotmail dot com

Not solved with PHP 5.3.4 (Windows / Apache 2)

------------------------------------------------------------------------
[2010-10-31 03:32:12] paj...@php.net

@php at twinmail dot de

Use VC9 builds instead, from http://windows.php.net

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


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