AGG Software
Ask a question  Top  Previous  Next

"Cron" time format

The cron format is a simple yet powerful way to describe time and operation periodicity. The traditional (inherited from the Unix world) cron format consists of five fields separated with spaces:

 

<Second> <Minutes> <Hours> <Month days> <Months> <Weekdays>

 

Any of the five fields can contain the * (asterisk) character as its value. It stands for the entire range of possible values. For example, every minute, every hours and so on. You can also use the "nonstandard" ? character in the first four fields. See its description below.

 

Any field can contain a list of comma-separated values (for example, 1,3,7) or  an interval (subrange) of values defined by a hyphen (for example, 1-5).

 

You can use the / character after the asterisk (*) character or after an interval to specify the value increment. For example, you can use 0-23/2 in the "Hours" field to specify that the operation should be carried out every two hours (old version analog: 0,2,4,6,8,10,12,14,16,18,20,22). The value */4 in the "Minutes" field means that the operations must be carried out every four minutes. 1-30/3 is the same as 1,4,7,10,13,16,19,22,25,28.

 

You can use three-word abbreviations in the "Months" (Jan, Feb, ... , Dec) and "Weekdays" (Mon, Tue, ... , Sun) fields instead of numbers.

 

Examples

 

Note: the <Second> field equal 0 in all examples

 

Format

Description

* * * * *

every minute

59 23 31 12 5

one minute before the end of the year if the last day in the year is Friday

59 23 31 Dec Fri

one minute before the end of the year if the last day in the year is Friday (one more variant)

45 17 7 6 *

every year on the 7th of June at 17:45

0,15,30,45 0,6,12,18 1,15,31 * 1-5 *

00:00, 00:15, 00:30, 00:45, 06:00, 06:15, 06:30, 06:45, 12:00, 12:15, 12:30, 12:45, 18:00, 18:15, 18:30, 18:45, if it is the 1st, 15th or 31st of any month and only on workdays

*/15 */6 1,15,31 * 1-5

00:00, 00:15, 00:30, 00:45, 06:00, 06:15, 06:30, 06:45, 12:00, 12:15, 12:30, 12:45, 18:00, 18:15, 18:30, 18:45, if it is the 1st, 15th or 31st of any month and only on workdays (one more variant)

0 12 * * 1-5 (0 12 * * Mon-Fri)

at noon on workdays

* * * 1,3,5,7,9,11 *

every minute in January, March, May, July, September and November

1,2,3,5,20-25,30-35,59 23 31 12 *

on the last day in the year at 23:01, 23:02, 23:03, 23:05, 23:20, 23:21, 23:22, 23:23, 23:24, 23:25, 23:30, 23:31, 23:32, 23:33, 23:34, 23:35, 23:59

0 9 1-7 * 1

on the first Monday of every month at 9 in the morning

0 0 1 * *

at midnight on the 1st of every month

* 0-11 * *

every minute till noon

* * * 1,2,3 *

every minute in January, February and March

* * * Jan,Feb,Mar *

every minute in January, February and March

0 0 * * *

every day at midnight

0 0 * * 3

every Wednesday at midnight

 

You can use the nonstandard "?" character in the first four fields of the cron format. It stands for the start time, i.e. the question mark will be replaced with the start time during the field processing: minute for the minute field, hour for the hours field, month day for the month day field and month for the month field.

 

For example, if you specify:

 

? ? * * *

 

the task will be run at the moment of startup and will continue being run at the same time (if the user does not restart the program again, of course) – the question marks are replaced with the time the program was started at. For example, if you start the program at 8:25, the questions marks will be replaced like this:

 

25 8 * * * *

 

Here are some more examples:

 

? ? ? ? * - run _only_ at startup;
? * * * * - run at startup (for example, at 10:15) and continue being run in exactly one hour: at 11:15, 12:15, 13:15 and so on;
* ? * * * - run every minute during the startup hour;
*/5 ? * * * - run on the next day (if the cron is not restarted) at the same hour every minute and so on every day, once in five minutes, during the startup hour.



Copyright © 1999-2017, AGG Software.
All rights reserved.