Ben Borgers

Easiest way to add days to a PHP DateTime

December 9, 2020

If you have a PHP DateTime instance and want to add a certain number of days to it, you can use the modify method. Here's an example:

$date = new DateTime('NOW')->modify('+1 day');

Now, $date is a DateTime 1 day in the future from now.

You can substitute any number of days into the modify method, or make it a variable like this:

$date = new DateTime('NOW')->modify("+{$daysToAdd} days");

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗