Add 10 Minutes to 7:30am PHP
Question
I'm sure this question has been asked before, but I'm too frustrated to find it. All I want to do is add X amount of minutes to X o'clock.
So, in my case for example I have a time 7:30am that I want to add 2:20 (two minutes and 20 seconds) to. (specifically in those formats).
I've even done this before, but it seems like every time I try to hash out a new PHP time function it's like I've entered the land of formatting errors. Thanks for your input and I'm bookmarking this answer for the rest of my life.
Solution
Adding 2 minutes and 20 seconds to 7:30AM:
$dt = new DateTime('7:30 AM');
$dt->add(new DateInterval('PT2M20S'));
echo $dt->format('H:i:s')."\n";
Output:
07:32:20
OTHER TIPS
Convert it to a timestamp, add 600 seconds and convert it back.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow