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.
Parameter | Is Required | Description |
---|---|---|
object | Required. | DateTime object returned by date_create() |
interval | Required. | 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/* w ww.j a v a 2s .c om*/
$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.