date_interval_create_from_date_string()

date_interval_create_from_date_string() — Alias of DateInterval::createFromDateString().

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.3.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

date_interval_create_from_date_string() is an alias of DateInterval::createFromDateString(): same parameters, same return value.

Signature

date_interval_create_from_date_string(string $datetime): DateInterval|false

Parameters

ParameterTypeWhat it takes
$datetimestringA date with relative parts. Specifically, the relative formats supported by the parser used for DateTimeImmutable, DateTime, and strtotime() will be used to construct the DateInterval.

Return value

Returns DateInterval on success. Procedural style returns false on failure.

Example

A runnable snippet:

// Each set of intervals describes the same duration. $i = new DateInterval('P1D'); $i = DateInterval::createFromDateString('1 day'); $i = new DateInterval('P2W'); $i = DateInterval::createFromDateString('2 weeks'); $i = new DateInterval('P3M'); $i = DateInterval::createFromDateString('3 months'); $i = new DateInterval('P4Y'); $i = DateInterval::createFromDateString('4 years'); $i = new DateInterval('P1Y1D'); $i = DateInterval::createFromDateString('1 year + 1 day'); $i = new DateInterval('P1DT12H'); $i = DateInterval::createFromDateString('1 day + 12 hours'); $i = new DateInterval('PT3600S'); $i = DateInterval::createFromDateString('3600 seconds');

All PHP 8.5 built-in functions

Reference card built from the PHP manual page date_interval_create_from_date_string() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.