Get a Calendar from Command Line for Any Date, Month, Year

Feb 24, 2016 - 9 Comments

Get a calendar from the command line of Mac OS X

Though just about everyone has our phones glued to us with a dedicated calendar app, for users who spend considerable time in the command line it can be more efficient to stay put rather than stray to another app or pick up a different device to flip around in the calendar and find a given date. With the help of a simple command line calendar utility, you can generate a calendar instantly, which is great for quick reference for dates and occasions. Going further, you can even generate a calendar for any date, in any year, and for any month, whether it’s the current year and month, last year, sometime in the Roman empire, or deep in the distant future of House Atreides.


This is a simple command that works with Mac OS X and Linux, so even if you’re not too comfortable with the command line you can still follow along. On the Mac, open the Terminal application from /Applications/Utilities/ to get started.

Generating a Calendar from the Command Line for Any Date

At it’s most simple form, you can print a calendar of the current month by typing:

cal

This generates a calendar of the current month in the current year, showing which dates fall on which days. Nice and useful.

Generate a calendar from the command line

To get a calendar generated for a specific month in a specific year, use the following command syntax, replacing the numbers as appropriate for the given month and desired year:

cal 5 2018

You can go as far into the past or the future as you want, generating an accurate calendar for any month and any year. Feel like time traveling? Just put the date into the Calendar, it’s easy:

Get a calendar from the command line of Mac OS X

For the time travelers, the calendar limits at the year 9999, so if you’re hoping to go beyond that you may have an issue. Likewise, the calendar year begins at year 1, like most Gregorian calendars do, so you may not have much success trying to visit the dinosaurs with this utility.

You can also generate calendars in a nice easy to read ASCII format for an entire year, printing the months onto a grid that is scannable like so:

cal 2016

Generate a calendar for any date or year

Simple to generate, easy to read, and you don’t even need to refer to the Calendar app on the Mac or iPhone, it’s all right here in the Terminal.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. Sebby says:

    Let’s face it, lots of us are only using Macs because Unix. :)

    • Bill says:

      Absolutely, many advanced Mac users are on the platform because of the unix underpinnings. I know tons of Linux converts that have moved exclusively to the Mac for OS X command line combined with the excellent hardware.

      Also, for me anyway, typing ‘cal’ is easier than launching a dedicated Calendar app (which is kind of cruddy on the Mac anyway). Plus, cal works everywhere. Linux, FreeBSD, OS X / Darwin, you name it.

  2. John says:

    Try September 1752

    • Dale says:

      cal 9 1752 does not work properly.

      cal 8 1752 and cal 10 1752 works.

      Care to explain what’s up with September of that year?

      • Jeff says:

        In the British Empire, it was the only year with 355 days, as September 3 through September 13 were skipped when the Empire adopted the Gregorian calendar.

      • Adrian says:

        Up to 1582 the Julian calendar was used. It added the extra day into February (ie The leap year). However, it was found that this didn’t quite correct the solar based calendar. The Gregorian calendar (named after Pope Gregory who was pope at the time) amended the calendar so that when the calendar was a ‘century’ year ie 1800, 1900 there was no leap year even though it normally would have been. Except every 400 years, the leap year is added back in eg 2000, 2400, 2800 etc. Clear?
        In order to correct the accumulated error a Papal Bull (law) was issued to remove the days in October 1582 to bring the calendar back into alignment. However, this caused major upset as people believed that their lives were being shortened by 10 days…..However, not all countries made the switch at that time. The USA adjusted its calendar in September 1752 by this time the error was now 11 days. Turkey was the last country to adopt the Gregorian calendar in 1926. This adjustment was 13 days.

        • John says:

          Yup. That’s right. For more fun and games about when different countries switched to the Gregorian calendar, hunt out the calendar FAQ.

          On Linux, cal is internationalised so that in the UK, for example, the week begins on Monday. No one has bitten the bullet and built in the switch dates. Sweden would be interesting!

  3. RM says:

    Nice simple tip, thank you.

    On this note, if I do a cal 1 1970 will my computer seize up and explode? lol

  4. Dan says:

    And don’t forget the associated ncal command, which has additional tricks up its sleeve.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates