Welcome to stack overflow. Since PHP7 is available on many servers, you can use the comfortable date classes. The following example does exactly what you want. The classes used have been available since PHP5 (for several years).
$start = new DateTime('2020-01-31T23:00:00');
$end = (new DateTime('2020-01-31T23:00:00'))->modify('midnight +3 weekdays');
$interval = new DateInterval('PT1H');
$range = new DatePeriod($start, $interval, $end);
foreach ($range as $date) {
if ($date->format('N') == 6 || $date->format('N') == 7) {
continue;
}
var_dump($date->format('Y-m-d H:i:s'));
}
First we define a start and an end date. For this example I 've chosen last friday to demonstrate, that saturday and sunday are ignored. Don't let the three days of the week confuse you. We start at midnight on the start date to get the full two workdays including the whole start date. Since you wanted every single hour, we use the DateInterval
class and define an hourly interval. With start, end and the interval we can iterate through a range with the DatePeriod
class. In the loop we check, if the weekday (assuming that 6 is saturday and 7 is sunday) is saturday and sunday, the date will be modified until the next monday is reached. The output is every hour skipping the weekend.
Please have a look in the php documentation for date and time to understand what these classes can do for you and how they work. Don 't just copy this example.