1

Possible Duplicate:
PHP DateTime::days returns trash?

Ok, I don't get this... Could someone explain what I'm doing wrong here?

date_default_timezone_set('Europe/Oslo');

$a = new DateTime('2011-06-20 21:00:00');
$b = new DateTime('2011-06-21 05:30:00');

echo $a->format('Y-m-d H:i:s') . PHP_EOL;
echo $b->format('Y-m-d H:i:s') . PHP_EOL;

echo $a->diff($b)->format('%a days, %h hours, %i minutes and %s seconds');
echo $a->diff($b)->format('%y years, %m months, %d days, %h hours, %i minutes and %s seconds').PHP_EOL;

The output I get is:

2011-06-20 21:00:00
2011-06-21 05:30:00
6015 days, 8 hours, 30 minutes and 0 seconds
0 years, 0 months, 0 days, 8 hours, 30 minutes and 0 seconds

What is up with the days here? Shouldn't it be 0 in both cases?

Community
  • 1
  • 1
Svish
  • 152,914
  • 173
  • 462
  • 620

1 Answers1

0

It should, and it does on my system:

nanne@pustule:~$ cat test.php
<?
date_default_timezone_set('Europe/Oslo');

$a = new DateTime('2011-06-20 21:00:00');
$b = new DateTime('2011-06-21 05:30:00');

echo $a->format('Y-m-d H:i:s') . PHP_EOL;
echo $b->format('Y-m-d H:i:s') . PHP_EOL;

echo $a->diff($b)->format('%a days, %h hours, %i minutes and %s seconds');

//

nanne@pustule:~$ php test.php
2011-06-20 21:00:00
2011-06-21 05:30:00
0 days, 8 hours, 30 minutes and 0 seconds

As @pekka commented: it seems to be a bug in PHP for windows systems :D

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • Yep! Crazy annoying... I mean, come on PHP people, that's a bug that should be fixed long ago! – Svish Jun 20 '11 at 20:27