ID: 49778 Comment by: awinningidea at gmail dot com Reported By: jenwelsh at yahoo dot com Status: Assigned Bug Type: Date/time related Operating System: Solaris 10 PHP Version: 5.3.0 Assigned To: derick New Comment:
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) Previous Comments: ------------------------------------------------------------------------ [2009-10-05 18:49:57] der...@php.net It's a bug, it should set this value really. ------------------------------------------------------------------------ [2009-10-05 16:31:59] sjo...@php.net Derick, how would you solve this? ------------------------------------------------------------------------ [2009-10-05 16:29:44] sjo...@php.net Thank you for your bug report. 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. ------------------------------------------------------------------------ [2009-10-05 14:37:27] 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 14:32:08] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49778&edit=1