PHP :: Bug #49778 :: DateInterval::format("%a") is always zero
| Bug #49778 | DateInterval::format("%a") is always zero | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2009-10-05 14:32 UTC | Modified: | 2010-03-07 19:00 UTC |
|
||||||||||
| From: | jenwelsh at yahoo dot com | Assigned: | derick (profile) | |||||||||||
| Status: | Closed | Package: | Date/time related | |||||||||||
| PHP Version: | 5.3.0 | OS: | Solaris 10 | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[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
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-10-05 14:37 UTC] jenwelsh at yahoo dot com
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");//7[2009-10-05 16:29 UTC] Sjoerd@php.net
[2009-10-05 16:31 UTC] Sjoerd@php.net
[2009-10-05 18:49 UTC] derick@php.net
[2009-11-17 19:23 UTC] awinningidea at gmail dot com
PHP 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)[2010-01-26 17:51 UTC] hellbringer at gmail dot com
$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 // )[2010-02-22 22:40 UTC] johnphayes at gmail dot com
[2010-03-02 12:13 UTC] yoarvi at gmail dot com
[2010-03-07 16:27 UTC] derick@php.net
-Status: Assigned +Status: Closed
[2010-03-07 16:27 UTC] derick@php.net