Skip to content
Advertisement

Tag: hour

How to I get a range of times from a start time and end times with an hour difference using PHP?

$course_hour = 1; $starttime = ’07:00′; $endtime = ’16:00′; I wish if it could return an array of values like below: If $return_array = array(’07:00 – 08:00′, ’08:00 – 09:00′, ’09:00 – 10:00′, ’10:00 – 11:00′, ’11:00 – 12:00′, ’12:00 – 13:00′, ’13:00 – 14:00′, ’14:00 – 15:00′, ’15:00 – 16:00′); If $return_array = array(’07:00 – 08:30′, ‘8:30 – 10:00’,

Add ‘x’ number of hours to date

I currently have php returning the current date/time like so: What I’d like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800. Any suggestions? Answer You may use something like the strtotime() function to add something to the current timestamp. $new_time = date(“Y-m-d H:i:s”, strtotime(‘+5

Advertisement