Попробуйте этого плохого мальчика.
Вы можете указать, включать ли выходные в качестве рабочих дней и т. Д. Не учитывает праздничные дни.
<?php
function addWorkingHours($timestamp, $hoursToAdd, $skipWeekends = false)
{
// Set constants
$dayStart = 8;
$dayEnd = 16;
// For every hour to add
for($i = 0; $i < $hoursToAdd; $i++)
{
// Add the hour
$timestamp += 3600;
// If the time is between 1800 and 0800
if ((date('G', $timestamp) >= $dayEnd && date('i', $timestamp) >= 0 && date('s', $timestamp) > 0) || (date('G', $timestamp) < $dayStart))
{
// If on an evening
if (date('G', $timestamp) >= $dayEnd)
{
// Skip to following morning at 08XX
$timestamp += 3600 * ((24 - date('G', $timestamp)) + $dayStart);
}
// If on a morning
else
{
// Skip forward to 08XX
$timestamp += 3600 * ($dayStart - date('G', $timestamp));
}
}
// If the time is on a weekend
if ($skipWeekends && (date('N', $timestamp) == 6 || date('N', $timestamp) == 7))
{
// Skip to Monday
$timestamp += 3600 * (24 * (8 - date('N', $timestamp)));
}
}
// Return
return $timestamp;
}
// Usage
$timestamp = time();
$timestamp = addWorkingHours($timestamp, 6);