1

Пишу скрипт для крона. Задача срабатывать каждый понедельник, среду, пятницу в 10:00. Cron будет запускать этот скрипт каждые 5 минут.

$startTime = date("Y-m-d H:i:s");

$current_plus = date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime($startTime)));
$current_minus = date('Y-m-d H:i:s', strtotime('-5 minutes', strtotime($startTime)));

if ((strtotime($current_plus) >= $pn_or_sr_or_pt_10_00) and (strtotime($current_minus) <= $pn_or_sr_or_pt_10_00))
{ 
...
}

Как получить это время для сравнения? $pn_or_sr_or_pt_10_00?

1 ответ 1

1

date позволяет получить день недели и часы-минуты

$check_day = in_array(date('N'), [1,3,5]);
$check_time = date('Hi') < 1005 and date('Hi') > 955;
if ($check_day and $check_time) {
    // code to run
}
1
  • Огромное спасибо!
    – Oleksii
    22 апр 2020 в 9:45

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.