Simple question but this is killing my time.
Any simple solution to add 30 minutes to current time in php with GMT+8?
asked Jun 12, 2009 at 9:27
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.
isherwood
54.1k15 gold badges105 silver badges147 bronze badges
answered Jun 12, 2009 at 13:53
KhrizKhriz
5,7185 gold badges33 silver badges38 bronze badges
1
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 wantanswered Dec 22, 2009 at 19:13
mnsmns
7095 silver badges3 bronze badges
1
Time 30 minutes later
$newTime = date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")." +30 minutes"))answered Apr 1, 2014 at 10:02
MaxEchoMaxEcho
14.1k6 gold badges78 silver badges88 bronze badges
$timeIn30Minutes = mktime(idate("H"), idate("i") + 30);
or
$timeIn30Minutes = time() + 30*60; // 30 minutes * 60 seconds/minuteThe result will be a UNIX timestamp of the current time plus 30 minutes.
answered Jun 12, 2009 at 10:04
Stefan GehrigStefan Gehrig
81.5k24 gold badges155 silver badges185 bronze badges
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...)
answered Jun 29, 2012 at 7:04
sarahsarah
931 silver badge12 bronze badges
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)
Sriram
9,94420 gold badges79 silver badges135 bronze badges
answered Jun 12, 2009 at 9:50
a_m0da_m0d
11.9k15 gold badges54 silver badges77 bronze badges
4
$ck=2016-09-13 14:12:33; $endtime = date('H-i-s', strtotime("+05 minutes", strtotime($ck)));
answered Sep 13, 2016 at 10:22
priyapriya
211 bronze badge
$dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata')); echo $dateTime->modify("+10 minutes")->format("H:i:s A");
David Buck
3,60033 gold badges29 silver badges34 bronze badges
answered Mar 27, 2020 at 18:23
1
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)));answered Oct 14, 2013 at 14:46
RafaSashiRafaSashi
15.7k8 gold badges79 silver badges90 bronze badges
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");answered May 25, 2017 at 9:06
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') ?>answered Jul 30, 2017 at 6:15
Lawrence CheroneLawrence Cherone
45.1k7 gold badges58 silver badges102 bronze badges
new DateTime('+30minutes')
As simple as the accepted solution but gives you a DateTime object instead of a Unix timestamp.
answered Jun 18, 2021 at 12:26
$time = strtotime(date('2016-02-03 12:00:00')); echo date("H:i:s",strtotime("-30 minutes", $time));
Robert
5,24743 gold badges63 silver badges114 bronze badges
answered Feb 3, 2016 at 12:00
1