Add minutes to date time in PHP
Question: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
Finally, you only need to add this interval to the
DateTime object you have already created.
Reference:PHP DateInterval reference
Share "How to add minutes to date time in PHP?"
- Add minutes to date time in PHP
- Add days to date in PHP
- Get same day in the next week in PHP
- Get time difference in minutes in PHP
- Convert date to timestamp in PHP
- Convert timestamp to DateTime in PHP
- Get the last day of a month from date in PHP
- Get the number of days between two dates in PHP
- Get yesterday's date in PHP
- Get tomorrow's date in PHP
- Get current time in PHP
- Get actual date in PHP
Tags:adding minutes to date, adding minutes to time, adding minutes to date time
Technical term:Add minutes to date time in PHP