- Instant help with your Php coding problems

Add minutes to date time in PHP

How to add minutes to date time in PHP?
$time = new DateTime(2020-12-18 11:23);
$time->add(new DateInterval("PT150M"));

echo $time->format('Y-m-d H:i:s');

Adding any minutes to a given time is very similar to adding any days to a given date. You only need to use the specific DateInterval format string.

First, create a DateTime object from your base time. Then create a DateInterval with the appropriate format string that looks like this: 'PT' + NUMBER_OF_MINUTES + 'M' . For example, if you want to add 150 minutes the format string is PT150M .

Finally, you only need to add this interval to the DateTime object you have already created.

Share "How to add minutes to date time in PHP?"
Interesting things
ChatGPT in a nutshell