0

I want to generate 3 time-period-list column between two times.

if
$start_time = '08:00 AM';
$end_time = '10:00: PM';

Time Period List As: 

Morning ----- Noon ----- Eve
8:00 AM       1:00 PM    6:00 PM
8:30 AM       1:30 PM    6:30 PM
9:00 AM       2:.0 PM    7:00 PM
to            to         to
...           ...        ...
12:00 PM      5:00 PM    10:00 PM

I have calculated times between $start_time and $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 to divide these times in three column as mention above

Thanks in advance to all my mates.

Frank
  • 2,285
  • 7
  • 43
  • 68

1 Answers1

0

You can use strtotime method to add and substract time period from given time. For example:

$time = strtotime('10:00'); 
$halfAnHourBefore = date("H:i", strtotime('-30 minutes', $time)); 
$halfAnHourAfter = date("H:i", strtotime('+30 minutes', $time)); 

would give $halfAnHourBefore as 09:30 and $halfAnHourAfter as 10:30

Rutesh Makhijani
  • 17,065
  • 2
  • 26
  • 22