- Instant help with your Php coding problems

Add days to date in PHP

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

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

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?"
Interesting things
ChatGPT in a nutshell