[php] PHP Date Time Current Time Add Minutes

Simple question but this is killing my time.

Any simple solution to add 30 minutes to current time in php with GMT+8?

This question is related to php

The answer is


$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata')); 
echo $dateTime->modify("+10 minutes")->format("H:i:s A");

echo $date = date('H:i:s', strtotime('13:00:00 + 30 minutes') );

13:00:00 - any inputted time

30 minutes - any interval you wish (20 hours, 10 minutes, 1 seconds etc...)


$ck=2016-09-13 14:12:33;
$endtime = date('H-i-s', strtotime("+05 minutes", strtotime($ck)));  

$timeIn30Minutes = mktime(idate("H"), idate("i") + 30);

or

$timeIn30Minutes = time() + 30*60; // 30 minutes * 60 seconds/minute

The result will be a UNIX timestamp of the current time plus 30 minutes.


Time 30 minutes later

$newTime = date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")." +30 minutes"))

This is an old question that seems answered, but as someone pointed out above, if you use the DateTime class and PHP < 5.3.0, you can't use the add method, but you can use modify:

$date = new DateTime();
$date->modify("+30 minutes"); //or whatever value you want

It looks like you are after the DateTime function add - use it like this:

$date = new DateTime();
date_add($date, new DateInterval("PT30M"));

(Note: untested, but according to the docs, it should work)


In addition to Khriz's answer.

If you need to add 5 minutes to the current time in Mysql format you can do:

$cur_time=date("Y-m-d H:i:s");
$duration='+5 minutes';
echo date('Y-m-d H:i:s', strtotime($duration, strtotime($cur_time)));

The question is a little old, but I come back to it often ;p

Another way, which is also a one liner:

<?= date_create('2111-11-11 00:00:00')->modify("+30 minutes")->format('Y-m-d h:i:s') ?>

Or from timestamp, returns Y-m-d h:i:s:

<?= date_create('@'.time())->modify("+30 minutes")->format('Y-m-d h:i:s') ?>

Or from timestamp, returns timestamp:

<?= date_create('@'.time())->modify("+30 minutes")->format('U') ?>

$time = strtotime(date('2016-02-03 12:00:00'));
        echo date("H:i:s",strtotime("-30 minutes", $time));

time after 30 min, this easiest solution in php

date('Y-m-d H:i:s', strtotime("+30 minutes"));

for DateTime class (PHP 5 >= 5.2.0, PHP 7)

$dateobj = new DateTime();
$dateobj ->modify("+30 minutes");