DateTime::createFromFormat

date_create_from_format

Parses a time string according to a specified format

&reftitle.description;

&style.oop;

public static ``DateTime``false```DateTime::createFromFormat` `string` `format` `string` `datetime` ``DateTimeZone``null```timezone`&null;

&style.procedural;

``DateTime``false```date_create_from_format` `string` `format` `string` `datetime` ``DateTimeZone``null```timezone`&null;

Returns a new DateTime object representing the date and time specified by the `datetime` string, which was formatted in the given `format`.

Like `DateTimeImmutable::createFromFormat` and `date_create_immutable_from_format`, respectively, but creates a `DateTime` object.

This method, including parameters, examples, and considerations are documented on the DateTimeImmutable::createFromFormat page.

&reftitle.parameters;

See DateTimeImmutable::createFromFormat.

&reftitle.returnvalues;

Returns a new DateTime instance&return.falseforfailure;.

&reftitle.errors;

This method throws ValueError when the `datetime` contains NULL-bytes.

&reftitle.changelog;

&Version; | &Description;
8.0.21, 8.1.8, 8.2.0 | Now throws ValueError when NULL-bytes are passed into `datetime`, which previously was silently ignored.

&reftitle.examples;

For an extensive set of examples, see DateTimeImmutable::createFromFormat.

&reftitle.seealso;

- `DateTimeImmutable::createFromFormat`