I have scheduled task which working is fine. every 2 hours , from 7:59, to 18:01.
$schedule->call('App\Http\Controllers\Controller@function')->everyTwoHours()->between('7:59', '18:01');
However , I only want it to run from Monday to Friday so I added weekdays()
$schedule->call('App\Http\Controllers\Controller@function')->weekdays()->everyTwoHours()->between('7:59', '18:01');
But unfortunately if will start from 00:00 every weekdays. This is not what I want. I want it to start from 8 am to 6pm every 2 hours.
--------- --------------- ------------- ----------------------------
| Command | Interval | Description | Next Due |
--------- --------------- ------------- ----------------------------
| | 0 */2 * * 1-5 | | 2021-10-04 00:00:00 08:00 |
| | 0 */2 * * 1-5 | | 2021-10-04 00:00:00 08:00 |
--------- --------------- ------------- ----------------------------
Appreciate your help, Thanks
CodePudding user response:
In your controller add this if check:
if(date('D') == 'Sat' || date('D') == 'Sun') {
//does nothing
} else {
//your task
}