PHP'nin DateTime :: diff'ten agrega gün almak nasıl?

5 Cevap php
$now = new DateTime('now');
$tomorrow = new DateTime('tomorrow');
$next_year = new DateTime('+1 year');

echo "<pre>";
print_r($now->diff($tomorrow));
print_r($now->diff($next_year));
echo "</pre>";

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 10
    [i] => 17
    [s] => 14
    [invert] => 0
    [days] => 6015
)

DateInterval Object
(
    [y] => 1
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 6015
)

herhangi bir fikir neden 'günlük' gösterir 6015? neden bu gün sayısını göstermez? Ay gün sayısı değişen beri 1 yıl fark, benim için hiçbir şey ifade etmiyor.

5 Cevap

Takip etmek daha uygun hata raporu 6015 gün (Windows olmayan göründüğünde OK) bildirdiği Windows sorununa odaklanan #51184 olacaktır.

Geri bildirim yok sorun devam ederse (bir farklı bir konu ile ilgilidir) # 49778 için düzeltme bu etkiler ya da olmadığı konusunda henüz verilmiştir. Herkes burada bir göz atın ve bazı geribildirim sağlayabilir, bu sizin çok tür olacaktır.

Son php yükseltin. Bu hata sadece 5.3 VC6 php oluşur.

$now = new DateTime('now');

olmalıdır

$now = new DateTime(''2010-01-01 00:00:00'');

more in the manual http://nl3.php.net/manual/en/datetime.diff.php

http://bugs.php.net/bug.php?id=49778 burada konudur gibi Tamam, görünüyor.

its a bug http://bugs.php.net/bug.php?id=49778

Lütfen hata raporu için teşekkür ederiz.

Days is indeed not set when creating a DateInterval using the constructor. A complication with this is that it is impossible to determine the number of days when months or years are specified, since these vary in length. It is possible to fill in the days field in some cases and leave it 0 in others. In any case, it should be documented that the days field is not always available.