PHP date_interval_create_from_date_string() Function
Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time
Definition
In PHP, date_interval_create_from_date_string() builds a DateInterval object from a plain-English text like "3 days" or "1 year 2 months".
It is the procedural name for DateInterval::createFromDateString(). The interval can then be used with date_add(), date_sub(), or the add() and sub() methods.
Syntax
Call date_interval_create_from_date_string() with the values you need. Start with this line.
date_interval_create_from_date_string("1 year 2 months")
Returns a DateInterval with y set to 1 and m set to 2.
date_interval_create_from_date_string("2 weeks")
Returns a DateInterval where d is 14, because weeks become days.
This is a friendly alternative to ISO strings such as P3D. Both give you a DateInterval. If the text cannot be understood, the function returns false (and PHP 8.3 and later also shows a warning), so check the result before you use it.
add() returns a new object. The original $start is not changed.
Ten days after December 25 is January 4 of the next year.
Frequently Asked Questions
It creates a DateInterval object from a readable text such as "3 days" or "1 year 2 months". You can then add or subtract that interval from a date.
new DateInterval() needs an ISO 8601 duration like P3D. date_interval_create_from_date_string() accepts everyday text like "3 days". Both return a DateInterval.
Yes. If PHP cannot parse the text, it returns false. PHP 8.3 and later also emits a warning, so always check the result before using it.
The days property is only filled when an interval comes from date_diff(). Intervals created from text or ISO strings keep it as false, so use the d, m, and y properties instead.
Yes. It is the procedural alias of the static method DateInterval::createFromDateString(), and both give the same result.