Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

date_add()

Example

Add 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”);
?>

Definition and Usage

The date_add() function adds a specified number of days, months, years, hours, minutes, and seconds to a given date.

Syntax

date_add(object, interval)

Parameter Values

 

Parameter

Description

object

Required. Specifies a DateTime object obtained from date_create().

interval

Required. Specifies a DateInterval object.

Technical Details

Return Value:

Returns a DateTime object upon success; FALSE on failure.

PHP Version:

5.3+