PHP date_interval_create_from_date_string() Function

❮ PHP Date/Time Reference

Example

Use date_interval_create_from_date_string() to add 1 year and 35 days to a date:

<?php
$date = date_create('2019-01-01');
date_add($date, date_interval_create_from_date_string('1 year 35 days'));
echo date_format($date, 'Y-m-d');
?>
Try it Yourself »

Definition and Usage

The date_interval_create_from_date_string() function sets up a DateInterval from the relative parts of the string.


Syntax

date_interval_create_from_date_string(datetime)

Parameter Values

Parameter Description
datetime Required. Specifies a DateInterval

Technical Details

Return Value: Returns new DateInterval object
PHP Version: 5.3+

❮ PHP Date/Time Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.