php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48609 DateInterval::format() doesn't work
Submitted: 2009-06-19 17:19 UTC Modified: 2009-12-08 10:58 UTC
Votes:7
Avg. Score:3.4 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:3 (42.9%)
From: pierre dot inglebert at insa-rennes dot fr Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.0RC4 OS: Debian Lenny
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pierre dot inglebert at insa-rennes dot fr
New email:
PHP Version: OS:

 

 [2009-06-19 17:19 UTC] pierre dot inglebert at insa-rennes dot fr
Description:
------------
DateInterval::format method just returns the parameter given.

Reproduce code:
---------------
<?php

$date1 = new DateTime('2009-06-19 20:00:00');
$date2 = new DateTime('2009-06-19 20:00:40');

$diff = $date1->diff($date2,TRUE);

print_r($diff);

var_dump($diff->format('H:i:s'));
var_dump($diff->format('Y-m-d H:i:s'));

?>


Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 40
    [invert] => 0
    [days] => 0
)
string(5) "00:00:40"
string(11) "0000-00-00 00:00:40"



Actual result:
--------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 40
    [invert] => 0
    [days] => 0
)
string(5) "H:i:s"
string(11) "Y-m-d H:i:s"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-08 10:44 UTC] yoarvi at gmail dot com
According to the documentation for DateInterval::format (http://us.php.net/manual/en/dateinterval.format.php), the format specifiers need to be prefixed with a %.

var_dump($diff->format('%H:%i:%s'));
var_dump($diff->format('%Y-%m-%d %H:%i:%s'));

produces the expected result.
 [2009-12-08 10:58 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Indeed, they need to be prefixed with %.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 21:01:33 2024 UTC