Simple question but this is killing my time.
Any simple solution to add 30 minutes to current time in php with GMT+8?
Simple question but this is killing my time.
Any simple solution to add 30 minutes to current time in php with GMT+8?
I think one of the best solutions and easiest is:
date("Y-m-d", strtotime("+30 minutes"))
Maybe it's not the most efficient but is one of the more understandable.
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
$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.
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)
$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
echo $dateTime->modify("+10 minutes")->format("H:i:s A");
new DateTime('+30minutes')
As simple as the accepted solution but gives you a DateTime object instead of a Unix timestamp.