date_parse_from_format

FunctionParams and return types changed in PHP 8.0

Get info about given date formatted according to the specified format.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

date_parse_from_format Function synopsis

date_parse_from_format(string $format, string $datetime): array

Parameters

$format

Typestring

Documentation on how the $format is used, please refer to the documentation of DateTimeImmutable::createFromFormat. The same rules apply.

$datetime

Typestring

String representing the date/time.

Return value

Typearray

Returns associative array with detailed info about given date/time.

The returned array has keys for year, month, day, hour, minute, second, fraction, and is_localtime.

If is_localtime is present then zone_type indicates the type of timezone. For type 1 (UTC offset) the zone, is_dst fields are added; for type 2 (abbreviation) the fields tz_abbr, is_dst are added; and for type 3 (timezone identifier) the tz_abbr, tz_id are added.

The array includes warning_count and warnings fields. The first one indicate how many warnings there were. The keys of elements warnings array indicate the position in the given $datetime where the warning occurred, with the string value describing the warning itself. An example below shows such a warning.

The array also contains error_count and errors fields. The first one indicate how many errors were found. The keys of elements errors array indicate the position in the given $datetime where the error occurred, with the string value describing the error itself. An example below shows such an error.

The number of array elements in the `warnings` and
`errors` arrays might be less than
`warning_count` or `error_count` if they
occurred at the same position.

Changes to the date_parse_from_format Function

PHP 8.0

  • Return type added: array
  • Parameter type added for parameter #1 ($format): string
  • Parameter name of parameter #2 changed: $date to $datetime
  • Parameter type added for parameter #2 ($datetime): string
- date_parse_from_format($format, $date)
+ date_parse_from_format(string $format, string $datetime): array

date_parse_from_format Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes