php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74645 DateTime::format() and DateTimeInterval %i %s Leading Zeros and Documentation
Submitted: 2017-05-24 14:08 UTC Modified: 2017-05-24 14:15 UTC
From: jimgkraai at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.30 OS: redhat 2.6.32-696.1.1.el6.x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jimgkraai at gmail dot com
New email:
PHP Version: OS:

 

 [2017-05-24 14:08 UTC] jimgkraai at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.format
---
DateTime::format() does not add leading zeros for the %i and %s format characters as documented.

https://secure.php.net/manual/en/datetime.format.php "Parameters/format" states "Format accepted by date()."  

https://secure.php.net/manual/en/datetime.format.php states 
- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
- 'S' is not in the list of format characters

The actual behavior of DateTime::format() is not properly documented.

Note that similar behavior/documentation dissonance exists for DateTimeInterval::format()


Test script:
---------------
<?php

$time_start = new DateTime('now');
sleep(60*2+3.1415926535897961646);
$time_end = new DateTime('now');
$time_interval=$time_end->diff($time_start);
echo $time_interval->format("%H:%i:%s seconds") . PHP_EOL;
echo $time_interval->format("%H:%I:%S seconds") . PHP_EOL; // <- not documented for DateTime::format()



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-24 14:12 UTC] jimgkraai at gmail dot com
--https://secure.php.net/manual/en/datetime.format.php states 
--- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
--- 'S' is not in the list of format characters

should read

https://secure.php.net/manual/en/function.date.php states 
- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
- 'S' is not in the list of format characters
 [2017-05-24 14:15 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Date/time related
 [2017-05-24 14:16 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$time_interval is a DateInterval. It has its own format() with its own formatting rules.

http://php.net/manual/en/datetime.diff.php
http://php.net/manual/en/dateinterval.format.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 14:01:31 2025 UTC