Easiest way to add days to a PHP DateTime

January 24, 2021

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");

A quick favor: was anything I wrote incorrect or misspelled, or do you still have questions? Please use this form to let me know or ask for help!