php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80057 DateTimeImmutable::createFromFormat() does not populate time
Submitted: 2020-09-04 10:16 UTC Modified: -
From: bc at benjamin-cremer dot de Assigned:
Status: Closed Package: Date/time related
PHP Version: 8.0.0beta3 OS: linux
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: bc at benjamin-cremer dot de
New email:
PHP Version: OS:

 

 [2020-09-04 10:16 UTC] bc at benjamin-cremer dot de
Description:
------------
The current time is not populated when a DateTime object is created by createFromFormat with a format pattern that has no time part defined.


Given the following code:
var_dump(DateTimeImmutable::createFromFormat('Y-m-d', '2020-09-04'));

Output from 8.0.0beta2 and before:
object(DateTimeImmutable)#1 (3) {
  ["date"]=>
  string(26) "2020-09-04 10:28:48.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

Output from 8.0.0beta3:
object(DateTimeImmutable)#1 (3) {
  ["date"]=>
  string(26) "2020-09-04 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

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

var_dump(DateTimeImmutable::createFromFormat('Y-m-d', '2020-09-04')->format('His') > 0);

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-04 14:55 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2ee2335249d4bbeed27d60a59245a966d0580074
Log: Fixed bug #80057 (DateTimeImmutable::createFromFormat() does not populate time)
 [2020-09-04 14:55 UTC] derick@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Mar 11 06:01:29 2025 UTC