date - Calculate time period list between 2 time in php? -


i want generate 3 time-period-list column between 2 times.

if $start_time = '08:00 am'; $end_time = '10:00: pm'; time period list as: morning ----- noon ----- eve 8:00 1:00 pm 6:00 pm 8:30 1:30 pm 6:30 pm 9:00 2:.0 pm 7:00 pm to ... ... ... 12:00 pm 5:00 pm 10:00 pm 

i have calculated times between $start_time , $end_time as:

$time = time(); $rounded_time = $time % 900 > 450 ? $time += (900 - $time % 900): $time -= $time % 900; $start = strtotime('08:00 am'); $end = strtotime('10:00 pm'); for( $i = $start; $i <= $end; $i += 1800) { echo "<input name='start_time' type='radio' value='".date('g:i a', $i)."' />"." ".date('g:i a', $i)."<br>"; } 

remaining work divide these times in 3 column mention above

thanks in advance mates.

you can use strtotime method add , substract time period given time. example:

$time = strtotime('10:00'); $halfanhourbefore = date("h:i", strtotime('-30 minutes', $time)); $halfanhourafter = date("h:i", strtotime('+30 minutes', $time)); 

would give $halfanhourbefore 09:30 , $halfanhourafter 10:30


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -