Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

date_interval_create_from_date_string()

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’);
?>

Definition and Usage

The date_interval_create_from_date_string() function creates a DateInterval object based on the relative parts specified in the string.

Syntax

date_interval_create_from_date_string(datetime)

Parameter Values

 

Parameter

Description

datetime

Required. Specifies a DateInterval.

Technical Details

Return Value:

Returns a new DateInterval object.

PHP Version:

5.3+