Skip to content

PHP 8.1 - DateTime::createFromFormat returns false #8652

@capsandiego

Description

@capsandiego

Description

The following code (which works perfectly in PHP 8.0:

<?php
var_dump(DateTime::createFromFormat('z Y', '147 2022'));

Resulted in this output:

bool(false)

But I expected this output instead:

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2022-05-28 15:36:32.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "America/New_York"
}

The only way to make it work is to swap day of the year and year.

PHP Version

PHP 8.1.6

Operating System

Ubuntu Server 18.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions