How to get aggregate days from PHP's DateTime::diff?

Posted by razic on Stack Overflow See other posts from Stack Overflow or by razic
Published on 2010-03-25T20:49:31Z Indexed on 2010/03/25 20:53 UTC
Read the original article Hit count: 155

Filed under:
|
$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
)

any ideas why 'days' shows 6015? why won't it show the total number of days? 1 year difference means nothing to me, since months have varying number of days.

© Stack Overflow or respective owner

Related posts about php

Related posts about datetime