PHP Tutorial - PHP date_add() Function






Definition

The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.

Syntax

PHP date_add() Function has the following syntax.

date_add(object,interval);

Parameter

PHP date_add() Function has the following syntax.

ParameterIs RequiredDescription
objectRequired.DateTime object returned by date_create()
intervalRequired.DateInterval object

Return

PHP date_add() Function returns a DateTime object on success. FALSE on failure.





Example

Add 40 days to the 15th of March, 2013


<?php
$date=date_create("2013-03-15");
date_add($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
?>

The code above generates the following result.