Introduction
Century codes and day formulas (like Zeller’s Rule) let you compute the weekday for any Gregorian calendar date quickly and reliably. This pattern is important because it provides a formulaic, exam-friendly method that avoids long year-by-year counting and works well for dates across centuries.
Pattern: Century Code & Day Formula (Zeller’s Rule)
Pattern
The key idea: Convert the date into components (day, adjusted month, year-of-century and century), apply month and century codes plus the year's contribution and leap adjustments, sum them, and take modulo 7 to get the weekday.
We use Zeller’s congruence (Gregorian calendar) with months March = 3 … December = 12, and January/February treated as months 13/14 of the previous year.
Use the formula:
h = ( q + floor(13*(m+1)/5) + K + floor(K/4) + floor(J/4) + 5*J ) mod 7
where:
q= day of monthm= month (3 = Mar, …, 12 = Dec; Jan = 13, Feb = 14 of previous year)K= year of century (year % 100)J= zero-based century (floor(year / 100))h= 0 → Saturday, 1 → Sunday, 2 → Monday, … 6 → Friday
Step-by-Step Example
Question
What day of the week was 26 January 1950?
Solution
-
Step 1: Adjust month and year for Zeller
January is treated as month 13 of the previous year. So use:q = 26,m = 13, andyear = 1949. -
Step 2: Compute K and J
K = year % 100 = 1949 % 100 = 49.
J = floor(year / 100) = floor(1949 / 100) = 19. -
Step 3: Evaluate the formula components
floor(13*(m+1)/5) = floor(13*(14)/5) = floor(182/5) = 36floor(K/4) = floor(49/4) = 12floor(J/4) = floor(19/4) = 45*J = 5*19 = 95
h = ( q + 36 + K + 12 + 4 + 95 ) mod 7=(26 + 36 + 49 + 12 + 4 + 95) mod 7.
Total =222. -
Step 4: Reduce mod 7
222 mod 7 = 5. According to Zeller’s mapping,h = 5corresponds to Thursday (0 = Sat, 1 = Sun, 2 = Mon, 3 = Tue, 4 = Wed, 5 = Thu, 6 = Fri). -
Final Answer:
26 January 1950 was a Thursday. -
Quick Check:
Cross-check with an alternate odd-day method or historical calendar - both confirm Thursday. ✅
Quick Variations
1. Use Zeller’s with months mapped as Mar→3 … Jan→13, Feb→14 (and decrement year for Jan/Feb).
2. For faster head calculations you can precompute and memorize month codes and century codes, then use the simplified form: weekday = (day + month_code + year_code + century_code + leap_adjust) mod 7.
3. Tomohiko Sakamoto’s algorithm or the Doomsday rule are alternative methods that may be faster in mental calculation; pick the method you are most comfortable with.
4. Always verify the weekday mapping used by your formula (Zeller’s uses Saturday = 0).
Trick to Always Use
- If
month ≤ 2(Jan/Feb), add 12 tomonthand subtract 1 fromyearbefore computingKandJ. - Precompute
floor(13*(m+1)/5)values (month offsets) for m = 3..14 to avoid repeated division. - Memorize century adjustments (values of
5*Jandfloor(J/4)) for common centuries to speed up calculations. - Reduce large intermediate sums modulo 7 early to keep arithmetic small and avoid mistakes.
Summary
Summary
- Convert the date into
q, adjustedm,K, andJ. (For Jan/Feb use months 13/14 of the previous year.) - Apply Zeller’s formula:
h = ( q + floor(13*(m+1)/5) + K + floor(K/4) + floor(J/4) + 5*J ) mod 7. - Interpret
has weekday with mapping 0 = Sat, 1 = Sun, …, 6 = Fri. - Use precomputed month/century codes and reduce modulo 7 often to simplify manual work.
Example to remember: 26 January 1950 → Thursday.
