date_add

Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object

Syntax

date_add ( DateTime $object , DateInterval $interval ) : DateTime

Parameters

object

A DateTime object returned by date_create(). The function modifies this object.

interval

A DateInterval object

Return

Returns the DateTime object for method chaining or FALSE on failure.

Examples

<?

$object = date_create('2001-01-01');
$interval = date_interval_create_from_date_string('1 year 1 month 1 day');

$return = date_add($object, $interval);

echo date_format($object, 'Y-m-d') . PHP_EOL;
echo date_format($return, 'Y-m-d');

?>
2002-02-02
2002-02-02

PHP

Home Menu