In crontab does the Day of the Week field run from 0 - 6 or 1 -7?

I am seeing conflicting information on this. wikipedia states 0-6 and other sites I have seen are 1-7.

Also what would be the implication or either using 0 or 7 incorrectly? i.e. would the cron still run?

share|improve this question
up vote 189 down vote accepted

0 and 7 both stand for Sunday, you can use the one you want, so writing 0-6 or 1-7 has the same result (see comments in code below for a better example).

The numbers from 1 to 6 are fixed to Monday, ..., Saturday.

Graphically:

 ┌────────── minute (0 - 59)
 │ ┌──────── hour (0 - 23)
 │ │ ┌────── day of month (1 - 31)
 │ │ │ ┌──── month (1 - 12)
 │ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or
 │ │ │ │ │                1 - 7 => Monday - Sunday)
 ↓ ↓ ↓ ↓ ↓
 * * * * * command to be executed

Also, as suggested by @Henrik, it is possible to replace numbers by shortened name of days, such as MON, THU, etc.

Finally, if you want to specify day by day, you can separate days with commas, for example SUN,MON,THU will exectute the command only on sundays, mondays on thursdays.

More informations on Wikipedia.

share|improve this answer
4  
ok thats what i didnt realise Sunday can be a 0 or 7. thanks – Marty Wallace Sep 20 '13 at 14:40
2  
Be aware that you cannot do: Sat-Sun, only 6-7 or Sat,Sun – pkowalczyk Dec 4 '17 at 15:33

According to Cyril Bouthors answer here is a list of the English abbreviated day of the week, which can be used in place of numbers:

 0 -> Sun

 1 -> Mon
 2 -> Tue
 3 -> Wed
 4 -> Thu
 5 -> Fri
 6 -> Sat

 7 -> Sun

Having two numbers for Sunday (0 and 7) can be useful for writing weekday ranges starting with 0 or ending with 7.

Examples of Number or Abbreviation Use

The next four examples will do all the same and execute a command every Friday, Saturday, and Sunday at 9.15 o'clock:

15 09 * * 5,6,0             command
15 09 * * 5,6,7             command
15 09 * * 5-7               command
15 09 * * Fri,Sat,Sun       command
share|improve this answer

You can also use day names like Mon for Monday, Tue for Tuesday, etc. It's more human friendly.

share|improve this answer
    
This won't work for some distributions; testing with Ubuntu 14.04.3 LTS, I got "/tmp/crontab.Nuq9GE/crontab":24: bad day-of-week" – 0x4B1D Jan 6 '16 at 3:48
2  
@Nikita check for typos or extra spaces. I have both a "Mon-Fri" and a "Thu" in my crontab on Ubuntu 14.04.3 and both work just fine. I suspect if there's a space between any of the characters, you'd end up with an error. – Dale Anderson Feb 4 '16 at 18:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.