- Instant help with your Php coding problems

Add minutes to date time in PHP

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

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

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?"