|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-05 14:32 UTC] jenwelsh at yahoo dot com
Description:
------------
DateInterval cannot output the total days. It always outputs 0.
Reproduce code:
---------------
---
From manual page: dateinterval.format#Return Values
---
$i=new DateInterval('P7D');
print_r($i);
echo $i->format("%d");
echo $i->format("%a");
Expected result:
----------------
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 7
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 0
)
7
7
Actual result:
--------------
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 7
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 0
)
7
0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
DateInterval::format with %a format does work if the DateInterval is the result of getting the difference between two DateTime objects: $d1=date_create('2009-11-02'); $d2=date_create('2009-11-09'); $i=$d2->diff($d1); echo $i->format("%d");//7 echo $i->format("%a");//7PHP 5.3 on windows, DateInterval::format('%a') gives 6015 for all dates. Example =============================== $d1 = new DateTime('1/1/2009'); $d2 = new DateTime('1/5/2009'); $diff = $d1->diff($d2); var_dump($diff->format('%a')); Output ------------------------------- string '6015' (length=4)$d1 = new DateTime('2010-01-01'); $d2 = new DateTime('2010-01-26'); $diff = $d1->diff($d2); echo phpversion(); // 5.3.1 echo $_SERVER['SERVER_SOFTWARE']; // Apache/2.2.11 (Win32) PHP/5.3.1 echo $diff->format('%a'); // 6015 echo $diff->days; // 6015 print_r($diff); // DateInterval Object // ( // [y] => 0 // [m] => 0 // [d] => 25 // [h] => 0 // [i] => 0 // [s] => 0 // [invert] => 0 // [days] => 6015 // )