Cron Expressions

Cron expressions are used to configure schedule records  on the Service Schedule form. A cron expression is a string consisting of 6 or 7 fields separated by white space. A cron expression must include a value for seconds, minutes, hours, day of month, month, and day of week. The year is not mandatory.

See Also:

Fields and Values

Special Characters

Examples of Cron Expressions

 

Cron Expressions Fields and Values

FIELD NAME

MANDATORY?

ALLOWED VALUES

ALLOWED SPECIAL CHARACTERS

Seconds

Yes

0-59

, - * /

Minutes

Yes

0-59

, - * /

Hours

Yes

0-23

, - * /

Day of Month

Yes

1-31

, - * ? / L W

Month

Yes

1-12 or JAN-DEC

, - * ? /

Day of Week

Yes

1-7 or SUN-SAT

, - * ? / L #

Year

No

Empty, 1970-2099

, - * /

 

Cron Expressions Special Characters

SPECIAL CHARACTER

WHAT IT MEANS IN CRON EXPRESSION

*

Used to select all values in a field. For example, "*" in the minute field means "every minute" and "*" in the month field means every month.

?

Used to indicate no specific value, i.e., when the value doesn't matter. For example, if you want the instance to run on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, you would put "10" in the day-of-month field, and "?" in the day-of-week field.

-

 

Used to specify a range. For example, "10-12" in the hour field means "the hours 10, 11 and 12".

,

Used to specify additional values. For example, "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday."

/

Used to specify increments. For example, "5/15" in the seconds field means "run the instance every 15 seconds starting at second 5. This would be at the seconds 5, 20, 35, and 50". "1/3" in the day-of-month field means "run the instance every 3 days starting on the first day of the month".

L

("last") This character has different meaning in day of month and day of week. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last Friday of the month". When using the "L" option, it is important not to specify lists, or ranges of values.

W

("weekday") - used to specify the weekday (Monday-Friday) nearest the given day. For example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the instance will run on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not jump over the boundary of a month's days. The "W" character can only be specified when the day-of-month is a single day, not a range or list of days.

LW

 The L and W characters can be combined in the day-of-month field to specify "last weekday of the month".

#

Used to specify "the nth" day of the month.

For example, the value of "6#3" in the day-of-week field means "the third Friday of the month" (day 6 = Friday and "#3" = the 3rd one in the month).

"2#1" = The first Monday of the month

"4#5" = The fifth Wednesday of the month.

Note: If you specify "#5" and there is no 5th occurrence of the given day of the week in the month, then no run will occur that month.

 

Examples of Cron Expressions

0 0 12 * * ?  = Run at 12 PM (noon) every day.

0 15 10 ? * * = Run at 10:15 AM every day.

0 15 10 * * ? = Run at 10:15 AM  every day.

0 15 10 * * ? * = Run at 10:15 AM every day.

0 15 10 * * ? 2010 = Run at 10:15 AM every day during the year 2010.

0 * 14 * * ? = Run every minute starting at 2 PM and ending at 2:59 PM, every day.

0 0/5 14 * * ? = Run every 5 minutes starting at 2 PM and ending at 2:55 PM, every day.

0 0/5 14,18 * * ? = Run every 5 minutes starting at 2 PM and ending at 2:55 PM, AND run every 5 minutes starting at 6 PM and ending at 6:55 PM, every day.

0 0-5 14 * * ? = Run every minute starting at 2 PM and ending at 2:05 PM, every day.

0 10,44 14 ? 3 WED = Run at 2:10 PM and at 2:44 PM every Wednesday in the month of March.

0 15 10 ? * MON-FRI = Run at 10:15 AM every Monday, Tuesday, Wednesday, Thursday and Friday.

0 15 10 15 * ? = Run at 10:15 AM on the 15th day of every month.

0 15 10 L * ? = Run at 10:15 AM on the last day of every month.

0 15 10 ? * 6L = Run at 10:15 AM on the last Friday of every month.

0 15 10 ? * 6L = Run at 10:15 AM on the last Friday of every month.

0 15 10 ? * 6L 2002-2005 = Run at 10:15 AM on every last Friday of every month during the years 2002, 2003, 2004 and 2005.

0 15 10 ? * 6#3 = Run at 10:15 AM on the third Friday of every month.

0 0 12 1/5 * ? = Run at 12 PM (noon) every 5 days every month, starting on the first day of the month.

0 11 11 11 11 ? = Run every November 11th at 11:11 AM.