cron

how to create a cron expression for every 2 weeks


Here is a cron expression that I tried: 0 0 0 */14 * ?. It creates the following schedule:

Start Time:

Friday, September 8, 2017 1:25 AM

Next Times:

  1. Friday, September 15, 2017, 12:00 AM
  2. Friday, September 29, 2017, 12:00 AM
  3. Sunday, October 1, 2017, 12:00 AM
  4. Sunday, October 15, 2017, 12:00 AM
  5. Sunday, October 29, 2017, 12:00 AM

This expression is working for every 2 weeks in every month, but my requirement is it has to run for every 2 weeks. I mean after executing September 29th, the next date should be October 13, but it schedules for October 1.


Solution

  • There is no direct cron expression for every 2 weeks. I use the following cron expression, which is similar to 2 weeks, but not exactly for 2 weeks.

    cron expression for every 2 weeks on the 1st and the 15th of every month at 1:30 AM:

    30 1 1,15 * *