I want to add 3 minutes to a date/time variable I have, but I'm not sure how to do this. I made the variable from a string like this: (which is in the RFC 2822 date format btw)
$date = 2011-10-18T19:56:00+0200
I converted that string into date using this command:
$time = date_format(DateTime::createFromFormat("Y-m-d\TH:i:sO", $date), "G:i")
Now, I'd like to add 3 minutes to that variable, but I I'm not sure how. I've used the following command in my script before, but that applies to the current date/time, so I'm not sure how to use that for my time variable:
$currenttime = date('G:i', strtotime('+2 hours'));
So, how can I add three minutes to the $time variable?
Use the second parameter of
strtotime
to provide a reference time:Since you're using the DateTime object already, stick with it:
http://www.php.net/manual/en/dateinterval.construct.php
That being said my solution to a similar problem is this:
The thing is to add
P
when usingDateInterval
class, andT
before time entries. For your case you need to go withPT3M
for 3 minute addition. I was trying to add 2 hours and what I did was$time->add(new DateInterval('PT2H'));
.If you would look at the interval specs:
M
formonths
andM
forminutes
. That is why there is aT
in front of time.At least that's what I want to believe... 'O_O