7

PHP Class DateInterval has a property "days". According to the manual it returns "Total number of days the interval spans. If this is unknown, days will be FALSE."

In my case the code:

$d = new DateInterval('P1Y'); 
echo $d->days;

returns -99999

and a code like this

$a = DateTime::createFromFormat("d.m.Y", "01.01.2010");
$b = DateTime::createFromFormat("d.m.Y", "03.01.2010");

$d = $b->diff($a);
echo $d->days;

returns 6015

Did I misunderstand something?

Adnan
  • 25,882
  • 18
  • 81
  • 110
30thh
  • 10,861
  • 6
  • 32
  • 42

3 Answers3

7

DateInterval is buggy on windows platform. See bug #51183. The official answer seems to be "use VC9 builds instead for now".

meze
  • 14,975
  • 4
  • 47
  • 52
  • 2
    The bug was reported an year ago and they tagged it as "wont fix" because "It is not something we can easily fix". Are they sick!? – 30thh Feb 08 '11 at 13:39
2

I just run your examples and they should work. Specifically I got:

    $d = new DateInterval('P1Y');
    var_dump($d->days);
    // result: int 0


    $a = DateTime::createFromFormat("d.m.Y", "01.01.2010");
    $b = DateTime::createFromFormat("d.m.Y", "03.01.2010");

    $d = $b->diff($a);
    var_dump($d->days);
    // result: int 2

I'm running XAMPP for Linux 1.7.3a with PHP 5.3.1 on Linux Mint 10.

Marcin
  • 215,873
  • 14
  • 235
  • 294
0

Can u please tell me your exact solution you need...

I have used the code below,

$interval = new DateInterval('P2Y4DT6H8M');

echo $interval->d;

it gives the o/p as 4

if i use like this,

$interval = new DateInterval('P2Y');

echo $interval->d;

it gives o/p as 0

So it will return the day u have given in Dateinterval() otherwise it will return zero..

U tell me ur exact requirement please.......... :)

Vinoth13
  • 397
  • 3
  • 7
  • 16
  • I am speaking not about "->d", but about "->days". According to manual it must be a total number of days, but it is not... at least not in Windows. – 30thh Feb 08 '11 at 13:56