Search code examples
phpcronlaravel-5.3

How to set up Laravel schedule job on Monday and Wednesday


How to schedule the job which needs to be run on custom days in Laravel.

eg) Monday and Wednesday only.

Wondering will it work or not?

 $schedule->command('report:sendEmail')->timezone('America/New_York')->weekdays()->mondays()->wednesdays()->dailyAt('21:30'); 

Solution

  • What about this one.

     $schedule->command('report:sendEmail')->timezone('America/New_York')->cron('30 21 * * 1,3');
    

    Above is the command to run your job at every Monday and Wednesday at 9:30 PM.

    Below is the format of cron job

    # Use the hash sign to prefix a comment
    # +---------------- minute (0 - 59)
    # |  +------------- hour (0 - 23)
    # |  |  +---------- day of month (1 - 31)
    # |  |  |  +------- month (1 - 12)
    # |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
    # |  |  |  |  |
    # *  *  *  *  *  command to be executed
    #--------------------------------------------------------------------------
    

    I suggest you to use http://corntab.com/ for creating cron rules in future.:)