I have a database table storing opening hours of a restaurant as a time range in TIME format. Eg if the restaurant\'s opening hours are \'9am-5pm\', there will be 2 columns
ON my current project I had to loop trough the 24 hours of the day ... and wanted them to be displayed in a certain format.
$interval = new DateInterval('PT1H'); // creating the interval for 1hour
$date = new DateTime();
$end = clone($date);
$hoursRange = new DatePeriod($date, $interval ,$end->modify("+24 hours"));
And then all I had was to iterate trough the hoursRange values using a foreach.
foreach ($hoursRange as $key => $value)
{
echo $value->format('ga');
}