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/* 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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions