Php – adding 30 minutes to date

datephptimestamp

So what I need to do is add 30 minutes to the following

date("Ymdhis");

I tried this

+strtotime("+30 minutes");

however it does not seem to like it. I wondering what the correct why to do this is.

Best Solution

Your method of using strtotime should work.

<?php

echo date("Y/m/d H:i:s", strtotime("now")) . "\n";
echo date("Y/m/d H:i:s", strtotime("+30 minutes"));

?>

Output

2012/03/22 10:55:45
2012/03/22 11:25:45 // 30 minutes later

However your method of adding time probably isn't correct. The above will work to add 30 minutes to the current time. Suppose you want to add 30 minutes from a given time, $t, then use strtotime's second parameter, which is used as a base for the calculation of relative dates.

date("Y/m/d H:i:s", strtotime("+30 minutes", $t));

http://codepad.org/Z5yquF55