Home >>PHP Date Time Functions >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 | 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>
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>