- Instant help with your Php coding problems

Add days to date in PHP

How to add days to date in PHP?
$date = new DateTime('2020-11-24');
$date->add(new DateInterval("P9D"));

echo $date->format('Y-m-d');

You can add any number of days to a given date using DateTime 's add method and the appropriate DateInterval . First, create a DateTime object from the base date. Then create a DateInterval object with a constructor parameter in a format 'P' + NUMBER_OF_DAYS + 'D' . For example, if you want to add 9 days then the format string is P9D . Then all you have to do is add this interval to the original date using the add method.

Share "How to add days to date in PHP?"