Latest web development tutorials

PHP date_add () function

PHP Date / Time PHP Date / Time Reference Manual

Examples

Adding 40 days to March 15, 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");
?>

Running instance »

Definition and Usage

date_add () function to add the day, month, year, hours, minutes and seconds to a date.

grammar

date_add( object,interval);

参数 描述
object 必需。规定 date_create() 返回的 DateTime 对象。
interval 必需。规定 DateInterval 对象。

technical details

return value: If successful DateTime object, if it fails returns FALSE.
PHP version: 5.3+


PHP Date / Time PHP Date / Time Reference Manual