Home >>PHP Date Time Functions >PHP date_add() Function
PHP date_add() function is used to add some specified days, months, years, hours, minutes and seconds to a given Date. The given Date value is supplied as a DateTime object to the date_add() function and the interval which we want to add to this defined Date is supplied as a DateInterval object. It returns a DateTime object as output on success else FALSE on failure.
Syntax:
date_add(object, interval);
Parameter | Description |
---|---|
object | This is a required parameter. This parameter defines a DateTime object returned by date_create(). |
interval | This is a required parameter. This parameter a DateInterval object. |
Here is an example of date_add() function in PHP:
<html> <body> <?php $date=date_create("31-01-2020 01:22:07"); date_add($date,date_interval_create_from_date_string("200 days + 22 hours + 45 minutes")); echo date_format($date,"d-m-Y H:m:s"); ?> </body> </html>
Here is another example of date_add() function in PHP:
<html> <body> <?php $date=date_create("14-02-2020"); date_add($date,date_interval_create_from_date_string("274 days + 22 hours")); echo date_format($date,"Y-m-d H:m"); ?> </body> </html>