Creating time between start time and end time in interval of 30 Minutes in PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$starttime = '9:00'; // your start time $endtime = '21:00'; // End time $duration = '30'; // split by 30 mins $array_of_time = array (); $start_time = strtotime ($starttime); //change to strtotime $end_time = strtotime ($endtime); //change to strtotime $add_mins = $duration * 60; while ($start_time <= $end_time) // loop between time { $array_of_time[] = date ("h:i", $start_time); $start_time += $add_mins; // to check endtie=me } |
Test it now
1 2 3 |
echo '<pre>'; print_r($array_of_time); echo '</pre>'; |
Thanks this is awesome.
Thank you for your comment And I’m glad to hear that you find the articles useful.
Thanks
What if i add the time zone in the times. For example this time is in UTC and i converted this time to Newyork/losangles then end_date will be converted to next day. How can we handle this because while ($start_time <= $end_time) // loop between time this condition will not work here.
Thanks you so much !
Thank you so much
It cannot convert from PM to AM like –> From: 9:30 PM –> To: 10:30 AM (Range)
greate article