Zeller’s Congruence (The Algorithm)

When I started college in 1998, I was studying A-Level mathematics and was introduced to Zeller’s Algorithm. When I then started studying programming I though this would be a great algorithm to turn into a program(that program can be found here).

I have been thinking about projects which I wish to put up on this website and think this is one of those that is quite interesting and not that difficult to follow.

The Algorithm

The formula we will be using is one which has already been optimised for computers it is as follows:

In the above formula:

  • W represents the day of the week (0=Saturday, 1=Sunday, … ,6=Friday)
  • D is the day of the month
  • M is the month (3=March, 4=April, …, 13=January, 14=February)
  • Y is the Year

Note: in the above formula January and February are counted as months 13 and 14 of the previous year, for example:

1 January 2020 would be 1/13/2019 and 14 February 2020 would be 14/14/2019.

Let’s work through a few examples before tackling the program.

Let’s choose today’s date (24/5/2020) which we know is a Sunday.

Inserting

  • D = 24
  • M = 5
  • Y = 2020

Into the formula gives:

We get the result of 1 which maps to Sunday so it has worked. The next example will be for 1 January 2000 which i have looked up and was a Saturday. Remembering to make January the 13th month of the previous year. So

Inserting

  • D = 1
  • M = 13
  • Y = 1999

Gives