I need to run laravel cron for after every 2 weeks or 14 days. but not found any solution for this. I was also search on laravel documentation https://laravel.com/docs/5.5/scheduling and found this option
->weekly();
But it runs on weekly. I was search also other option and found this laravel schedule task to run every 10 days of a month But it work only first 10 days of a month
$schedule->command('log:test')->cron('0 0 1-10 * *');
Please help me if you have any solution thanks in advance.
Cron jobs are scheduled at recurring intervals, specified using a format based on unix-cron. You can define a schedule so that your job runs multiple times a day, or runs on specific days and months. (Although we no longer recommend its use, the legacy App Engine cron syntax is still supported for existing jobs.)
You can use daily() together with when() method and inside when add suitable constrain for your task. For example, run task every month on 1,16 days:
$schedule->command('sitemap:sitemap_xml_generate')->daily()->when(function () {
$days = [1,16];
$today = Carbon::today();
return in_array($today->day, $days);});
or you can use this
$schedule->command('sitemap:sitemap_xml_generate')->cron('0 0 1,16 * *');
cron('0 0 1,16 * *') -> Argument are 'minute hour day(we can specify multiple date seperated by comma) month year'
$schedule->command('command_name')->weekly()->mondays()
->when(function () {
return date('W') % 2;
})->at("13:38");
Function will return 1 in every two other weeks, So the command will be called in every two weeks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With