Simple question but this is killing my time. Show 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:
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:
answered Dec 22, 2009 at 19:13
mnsmns 7095 silver badges3 bronze badges 1 Time 30 minutes later
answered Apr 1, 2014 at 10:02
MaxEchoMaxEcho 14.1k6 gold badges78 silver badges88 bronze badges
or
The 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
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:
(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
answered Sep 13, 2016 at 10:22
priyapriya 211 bronze badge
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
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
for DateTime class (PHP 5 >= 5.2.0, PHP 7)
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:
Or from timestamp, returns Y-m-d h:i:s:
Or from timestamp, returns timestamp:
answered Jul 30, 2017 at 6:15
Lawrence CheroneLawrence Cherone 45.1k7 gold badges58 silver badges102 bronze badges
As simple as the accepted solution but gives you a DateTime object instead of a Unix timestamp. answered Jun 18, 2021 at 12:26
Robert 5,24743 gold badges63 silver badges114 bronze badges answered Feb 3, 2016 at 12:00
1 How to add minutes in current time in php?Example 1: PHP Add Minutes to Time. index.php. $date = "10:10:05"; $newDate = date('H:i:s', strtotime($date. ' +10 minutes')); ... . Output: 10:20:05.. index.php. $newDate = date('H:i:s', strtotime('+10 minutes')); echo $newDate; ?>. Output: Read Also: PHP Add Hours to Datetime Example. 04:05:51. i hope it can help you.... How to add hours and minutes to time in php?PHP | DateTime add() Function
The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object.
How to add minutes and seconds in php?php $time = "01:30:00"; list ($hr, $min, $sec) = explode(':',$time); $time = 0; $time = (((int)$hr) * 60 * 60) + (((int)$min) * 60) + ((int)$sec); echo $time; ?>
What is PHP time function?The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
|