I needed to determine the day of the week for a particular date several years in the past. Rather than page back through the years using a GUI calendar, I thought I'd do it from the command line on a Linux system to which I had logged in by SSH, but couldn't remember the format for the command to display the day of the week, so had to look it up. The
date command on a Linux system can be used to display
information for dates other than the current one.
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
display time described by STRING, not ‘now’There were several format options available to me.
| %a | locale’s abbreviated weekday name (e.g., Sun) |
| %A | locale’s full weekday name (e.g., Sunday) |
| %u | day of week (1..7); 1 is Monday |
| %w | day of week (0..6); 0 is Sunday |
I wanted to determine the day of the week for May 30, 2005, so I could
use YYYYMMDD, i.e., 20050530 for the date with
any of those format parameters.
$ date --date="20050530" +%a Mon $ date --date="20050530" +%A Monday $ date --date="20050530" +%u 1 $ date --date="20050530" +%w 1
A calendar can be displayed at a shell prompt using the cal
command as well that will show you the day of the week for a date using
ASCII
characters, e.g.:
$ cal 05 2005
May 2005
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31From that calendar, I can see that May 30 in 2005 was a Monday.
