Home >>PHP Date Time Functions >PHP date_interval_create_from_date_string() Function

PHP date_interval_create_from_date_string() Function

PHP date_interval_create_from_date_string() Function

PHP date_interval_create_from_date_string() function is used to set up a DateInterval from the relative part of the given string. It returns the new dateTime object as output.

Syntax:

date_interval_create_from_date_string($datetime);

Parameter Values

Parameter Description
datetime This is a required parameter. This parameter defines a DateInterval.

Here is an example of date_interval_create_from_date_string() function in PHP:

<html>
<body>

<?php

$date = date_create();
date_add($date, date_interval_create_from_date_string('1 year 14 days'));
echo date_format($date, 'd-m-Y  (l)');

?>

</body>
</html>
Output:
14-02-2021 (Sunday)

Example 2

<html>
<body>

<?php

$date = date_create();

$sate1 = date_add($date, date_interval_create_from_date_string('200 days'));
echo date_format($date, 'd-m-Y')."<br>";
$sate1 = date_add($date, date_interval_create_from_date_string('95 days'));
echo date_format($date, 'd-m-Y')."<br>";
$sate1 = date_add($date, date_interval_create_from_date_string('563 days'));
echo date_format($date, 'd-m-Y')."<br>";
$sate1 = date_add($date, date_interval_create_from_date_string('154 days'));
echo date_format($date, 'd-m-Y')."<br>";
$sate1 = date_add($date, date_interval_create_from_date_string('964 days'));
echo date_format($date, 'd-m-Y')."<br>";

?>

</body>
</html>
Output:
18-08-2020
21-11-2020
07-06-2022
08-11-2022
29-06-2025

No Sidebar ads