CalendarIQ uses Zeller's Congruence, a mathematical algorithm developed by Christian Zeller in 1882 to calculate the day of the week for any date.
The Formula
h = (q + ⌊13(m+1)/5⌋ + K + ⌊K/4⌋ + ⌊J/4⌋ - 2J) mod 7
Where:
- h is the day of the week (0 = Saturday, 1 = Sunday, ..., 6 = Friday)
- q is the day of the month
- m is the month (3 = March, 4 = April, ..., 14 = February)*
- K is the year of the century (year % 100)
- J is the zero-based century (year / 100)
*January and February are counted as months 13 and 14 of the previous year
Example: July 4, 1776
• q = 4 (day of month)
• m = 7 (July)
• K = 76 (1776 % 100)
• J = 17 (1776 / 100)
Result: Thursday
Why It Works
The algorithm accounts for leap years, century rules, and the irregular pattern of the Gregorian calendar. Each component adjusts for different calendar irregularities:
- The 13(m+1)/5 term handles varying month lengths
- K/4 accounts for leap years within a century
- J/4 - 2J handles the century leap year rule (divisible by 400)
Accuracy: This algorithm is accurate for all dates in the Gregorian calendar (adopted in 1582) and can calculate dates from 1900-2100 with 100% accuracy.