date_parse

FunctionParams and return types changed in PHP 8.0

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

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 Function synopsis

date_parse(string $datetime): array

Parameters

$datetime

Typestring

Date/time in format accepted by DateTimeImmutable::__construct.

Return value

Typearray

Returns array with information about the parsed 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.

If relative time elements are present in the $datetime string such as +3 days, the returned array includes a nested array with the key relative. This array then contains the keys year, month, day, hour, minute, second, and if necessary weekday, and weekdays, depending on the string that was passed in.

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.

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.

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 Function

PHP 8.0

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

date_parse 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