Search code examples
cron

Cron Expression for running job every 4 hours starting at 4pm . But should not run between 12am to 7am of the day


I am trying to create a Cron Expression for running job every 4 hours starting at 4pm, but should not run between 12am to 7am of the day. So far I tried to do this but it does not work.

0 0 16/4 ? 0-2,7-23 * * *

Solution

  • This could be your cron expression.

    0 0 16/4,20,8,12 ? * * *
    

    Use this link to get exactly what you are seeking for. It will also helps you with the next execution time.