In this article, you will learn how to add some days, months, years, hours, minutes, or seconds to a date. The PHP date_add() function does the job for us.
What is the syntax of the function in PHP?
date_add(object, interval)
Parameter | Description |
---|---|
object | DateTime object – Required |
interval | DateInterval object – Required |
Examples of date_add() function
Example 1. In the following example, we add 30 days to the 04 of January 1998.
<?php
$d=date_create("1998-01-04");
date_add($d,date_interval_create_from_date_string("30 days"));
echo date_format($d,"Y-m-d");
?>