DjmUK Posted February 3, 2006 Share Posted February 3, 2006 This is bugging me now. I can add, say, 20 minutes to the current time using: <? $mytime = ($start = date("H:i:s", strtotime( "$start + 20 mins"))); echo $mytime; } ?> But...how would one add 20 minutes to a specified time in text format: <? FROM $mytime = "18:00:00"; TO $mynewtime = "18:20:00"; ?> Thanks in advance. Link to comment Share on other sites More sharing options...
0 soil Posted February 3, 2006 Share Posted February 3, 2006 (edited) isnt it just something like... $var = date("H:is:") + 20000; :unsure: edit: nvm that doesnt work :p, ill go search about for u. edit again: couldnt find anything but u might need to do something with 'strtotime' :unsure: Edited February 3, 2006 by soil Driffdith 1 Share Link to comment Share on other sites More sharing options...
0 SkyyPunk Veteran Posted February 3, 2006 Veteran Share Posted February 3, 2006 use mktime function in php..i cant remember the order of the params, but it wouldbe something like $timeshift = mktime(yr,mo,day,hr,min+20,seconds); $val = date("H:i:s",$timeshift); codes not exactly right, you would have to stick in the yr, mo, etc...but you can do that by just like date('m') for the month (or whateever the month code is) or Link to comment Share on other sites More sharing options...
0 DjmUK Posted February 3, 2006 Author Share Posted February 3, 2006 I modified mktime() and it works now :D Thanks guys. Link to comment Share on other sites More sharing options...
0 Adrian Posted February 3, 2006 Share Posted February 3, 2006 <?php echo date("H:i:s", mktime()+(20*60)); ?> Link to comment Share on other sites More sharing options...
0 dimitris Posted March 19, 2010 Share Posted March 19, 2010 <?php echo date("H:i:s", mktime()+(20*60)); ?> and what user really needs (and didn't post) is this: $date = date("Y-m-d");//or equivalent $dateParts = explode("-", $date); $time = date("H:i:s");//or equivalent $timeParts = explode(":", $time); $duration = 20;//min echo date("H:i:s", mktime($timeParts[0], $timeParts[1], $timeParts[2], $dateParts[1], $dateParts[2], $dateParts[0])+($duration*60)); Link to comment Share on other sites More sharing options...
0 cold12 Posted April 14, 2010 Share Posted April 14, 2010 Just in case you want a solution that doesn't suck: $From = "18:00:00"; $Minutes = 20; $To = date("H:i:s", strtotime($From)+($Minutes*60)); Link to comment Share on other sites More sharing options...
0 Hot Posted April 14, 2010 Share Posted April 14, 2010 This thread follows a trend that bugs me. Every solution proposed so far calculates minutes * seconds. Unless the number of minutes you are adding is variable, there is no reason to have PHP do an extra calculation every time the script runs. If you must remind yourself how you go the value, leave a comment or something. $increment = 1200; //20 min * 60 sec Link to comment Share on other sites More sharing options...
Question
DjmUK
This is bugging me now. I can add, say, 20 minutes to the current time using:
But...how would one add 20 minutes to a specified time in text format:
Thanks in advance.
Link to comment
Share on other sites
7 answers to this question
Recommended Posts