DateInterval::createFromDateStringSets up a DateInterval from the relative parts of the string DescriptionObject-oriented style
public static DateInterval DateInterval::createFromDateString(string
$datetime)Procedural style DateIntervalfalse date_interval_create_from_date_string(string
$datetime)Uses the date/time parsers as used in the DateTimeImmutable constructor to create a DateInterval from the relative parts of the parsed string. Parameters
Return Values
Returns DateInterval on success.
Procedural style returns Errors/ExceptionsObject Oriented API only: If an invalid Date/Time string is passed, DateMalformedStringException is thrown. Changelog
Examples
Example #1 Parsing valid date intervals
Example #2 Parsing combinations and negative intervals The above example will output: 449 2 70 1 -10
Example #3 Parsing special relative date intervals Output of the above example in PHP 8.2:
object(DateInterval)#1 (2) {
["from_string"]=>
bool(true)
["date_string"]=>
string(22) "last day of next month"
}
object(DateInterval)#2 (2) {
["from_string"]=>
bool(true)
["date_string"]=>
string(12) "last weekday"
}
Output of the above example in PHP 8 is similar to:
object(DateInterval)#1 (16) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(2)
["invert"]=>
int(0)
["days"]=>
bool(false)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
object(DateInterval)#2 (16) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
bool(false)
["special_type"]=>
int(1)
["special_amount"]=>
int(-1)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(1)
}
|