PHP date_add() Function
In this chapter you will learn:
- Definition for PHP date_add() Function
- Syntax for PHP date_add() Function
- Parameter for PHP date_add() Function
- Return value from PHP date_add() Function
- Example - Add 40 days to the 15th of March, 2013
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// j av a 2 s . co m
$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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP date_create() Function
- Syntax for PHP date_create() Function
- Parameter for PHP date_create() Function
- Return value for PHP date_create() Function
- Example - Return a new DateTime object, and then format the date
- Example - Return a new DateTime object (with a given timezone), and then format the date and time
Home » PHP Tutorial » PHP Date Functions