PHP date_interval_create_from_date_string() function

PHP date_get_last_errors() function
PHP date_interval_format() function

In this article, you will learn how to create a DateInterval from a string. The PHP date_interval_create_from_date_string() function takes relative parts from the string to create the DateInterval.

What is the syntax of the date_interval_create_from_date_string() function in PHP?

date_interval_create_from_date_string(datetime)
ParameterDetails
datetimeDateInterval – Required
PHP date_interval_create_from_date_string() method

Examples of the date_interval_create_from_date_string() function

Example 1. In the following example, we create a date and then create an Interval using the date_interval_create_from_date_string function.

<?php
$d= date_create('2021-01-04');
date_add($date, date_interval_create_from_date_string('2 years 15 days'));
echo date_format($d, 'Y-m-d');
?>
PHP date_get_last_errors() function
PHP date_interval_format() function
en English
X
Scroll to Top