Чтобы проверить, находится ли время в определенном диапазоне с помощью PHP, вы можете использовать класс DateTime и связанные с ним методы. Вот несколько методов, которые вы можете использовать, а также примеры кода:
Метод 1. Использование объектов DateTime
$startTime = new DateTime('09:00:00');
$endTime = new DateTime('17:00:00');
$currentTime = new DateTime(); // current time
if ($currentTime >= $startTime && $currentTime <= $endTime) {
echo "The current time is within the specified range.";
} else {
echo "The current time is outside the specified range.";
}
Метод 2: использование функции strtotime
$startTime = strtotime('09:00:00');
$endTime = strtotime('17:00:00');
$currentTime = time(); // current time
if ($currentTime >= $startTime && $currentTime <= $endTime) {
echo "The current time is within the specified range.";
} else {
echo "The current time is outside the specified range.";
}
Метод 3. Использование форматирования даты
$startTime = strtotime('09:00:00');
$endTime = strtotime('17:00:00');
$currentTime = date('H:i:s'); // current time
if ($currentTime >= date('H:i:s', $startTime) && $currentTime <= date('H:i:s', $endTime)) {
echo "The current time is within the specified range.";
} else {
echo "The current time is outside the specified range.";
}
Не забудьте заменить «09:00:00» и «17:00:00» желаемым временем начала и окончания.