|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51866 DateTime::createFromFormat does not match documentation
Submitted: 2010-05-20 04:01 UTC Modified: 2010-05-22 21:23 UTC
From: smalyshev at sugarcrm dot com Assigned: salathe (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3SVN-2010-05-20 (SVN) OS: *
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.
Block user comment
Status: Assign to:
Bug Type:
From: smalyshev at sugarcrm dot com
New email:
PHP Version: OS:


 [2010-05-20 04:01 UTC] smalyshev at sugarcrm dot com
The manual for DateTime::createFromFormat says: 

 Format accepted by date().

If format does not contain the character ! then portions of the date/time value specified in format but not specified in time will be set to the current system time. 

However if you specify format like "d-m-Y H:i" and provide datetime string that does not contain time, parsing would fail - even though the manual says if time string does not contain parts from format it should use current system.

Test script:

$date = DateTime::createFromFormat("d-m-Y H:i", "25-10-2007");

Expected result:
Something like:
object(DateTime)#1 (3) {
  string(19) "2007-10-25 18:58:31"
  string(19) "America/Los_Angeles"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-20 04:02 UTC]
It also would be nice if this function could ignore extra input after the parsing and/or return where it stopped.
 [2010-05-20 10:20 UTC]
-Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: derick
 [2010-05-20 10:20 UTC]
I believe this is an issue of documentation rather than implementation, the quoted 
portion of the manual describes different behaviour than what the code appears to 
do.  I'll assign this to Derick to confirm one way or the other.
 [2010-05-21 00:05 UTC]
-Type: Documentation Problem +Type: Bug
 [2010-05-21 00:05 UTC]
I don't think it's a docs problem - it'd be much better if DateTime actually did what the docs say - at least as one of the options. Without it, if you have a string with date in it, you can not really find out where the date begins and ends and have no way to do parsing of partial dates.
 [2010-05-22 19:07 UTC]
-Assigned To: derick +Assigned To: salathe
 [2010-05-22 19:07 UTC]
The docs are wrong here. If you specify a format letter, that information needs to be there.
 [2010-05-22 21:13 UTC]
Automatic comment from SVN on behalf of salathe
Log: Correct description of special ! character. Fixes #51866
 [2010-05-22 21:23 UTC]
-Status: Assigned +Status: Closed -Type: Bug +Type: Documentation Problem
 [2010-05-22 21:23 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

The description of "!" now matches what the code does, as well as the example that was already available in the documentation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 14:01:33 2024 UTC