Search code examples
cronairflow-scheduler

To run in a time window until midnight


I have an AirFlow scheduler that I want to run at 13 until midnight from Monday to Saturday. I wrote an expression like this:

0 13-0 * * 1-6

While trying to validate this in crontab.guru for example I get an error since 0 is smaller than 13:

https://crontab.guru/

Does anyone know how can I write a valid cron-expression for this type of schedule?


Solution

  • If you would like to run your command at minute 00 from 13:00 onwards till midnight (inclusive) on all days except Sundays, then you have to play a trick. It is not possible to define the hour 24 in a crontab. You can define the hour 00, but a crontab of the form

    0 0,13-23 * * 1-6
    

    will run on Monday 00:00 and not on Sunday 00:00 which is what the OP really wants.

    Here are two methods you can use:

    1. Run two crontabs:

      0 13-23 * * 1-6
      0 0     * * 2-7
      
    2. Run a single crontab a minute earlier:

      59 12-23 * * 1-6