Skip to content
Advertisement

Get specific day of week of the upcoming Canada day on Linux

How to use cal command to add the calendar of next July to the end of the file, for example, myfile, and what day of the week the upcoming Canada Day fall on?

So far I just have this command:

cal July 2017 >> myfile

I feel like I am not doing it correct and I don’t know which command to use, to find the day of the week for specific date.

Advertisement

Answer

Use this command:

cal 7 2017 >> file

The output is:

     July 2017
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 31

You can find out day of week of a particular day with the GNU date command:

date -d"2017-07-01"              # what day of week is Canada Day this year?
=> Sat Jul  1 00:00:00 UTC 2017

If you just want the week day, then:

date -d"2017-07-01" +%A
=> Saturday

You can check more about these commands with man cal or man date.

On a Mac, you could do this:

date -j -vJulm -v1d -v2017y +%A

See more on this post: date command on Mac OS

Advertisement