date_add() : adds a specified interval to a DateTime object

Add calendar intervals to a date

DateTime::add() changes a mutable DateTime object, while DateTimeImmutable::add() returns a new object. DateInterval expresses the amount to add.

$start = new DateTimeImmutable('2026-09-14');
$next = $start->add(new DateInterval('P10D'));
echo $start->format('Y-m-d') . "
";
echo $next->format('Y-m-d');

Month and year additions follow calendar rules, so check end-of-month behavior when it matters to your application.

WE will learn how to add date time intervals to a date object. We must understand date interval and date format before using add function to the date object.

Use DateTimeImmutable when additions should return a new object without changing the original date. Use DateTime when in-place mutation is intentional.
Procedural style
$date = date_create('2019-01-05');
date_add($date, date_interval_create_from_date_string('15 days'));
echo date_format($date, 'Y-m-d'); // Output is 2019-01-20
Object oriented style.
$date1=new DateTime('2019-05-30'); // date object created. 
$new_date=$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months 
echo $new_date->format('Y-M-d'); // Output is 2020-Aug-30

Read more on how to prepare DateInterval()

Let us try to add 5 days to current date.
date_default_timezone_set ("Asia/Kolkata");
$date=new DateTime("now") ;
echo $date->format('d-m-y');
echo "<br>";
$date=$date->add(new DateInterval('P5D'));
echo $date->format('d-m-y ');
The output is here
20-10-26
25-10-26
We will add 1 Year, 3 months , 5 days to current date . We will only change the affected row in above code like this.
$date=$date->add(new DateInterval('P1Y3M5D'));
echo $date->format('m-d-y ');
Let us add hour minute and seconds to this date object.

date_default_timezone_set ("Asia/Kolkata");
$date=new DateTime("now") ;
echo $date->format('d-m-y H:i:s');
echo "<br>";
$date=$date->add(new DateInterval('P1Y3M5DT4H5M12S'));
echo $date->format('m-d-y H:i:s ');
Output is here ( Refresh this page to see the change in output)
20-10-26 10:37:35
01-25-28 14:42:47

Using DateTimeImmutable object

DateTimeImmutable never modifies itself but returns a new object instead
$date1=new DateTime('2019-05-30'); // date object created. 
$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months added
echo $date1->format('Y-M-d'); // Output is 2020-Aug-30
/// by using DateTimeImmutable ///
$date1=new DateTimeImmutable('2019-05-30'); // original object
$date2=$date1->add(new DateInterval('P1Y3M')); // returned object has new date
echo $date1->format('Y-M-d'); // 2019-May-30
echo $date2->format('Y-M-d'); // 2020-Aug-30
In case of date object created using DateTimeImmutable after adding the interval the original value never changes.
PHP Date Functions diff(): Difference in two dates


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer