TOPICS
Search

Calendar Arithmetic


Calendar arithmetic is the use of integer arithmetic and modular arithmetic to compute elapsed days, weekdays, and recurring date patterns. Assigning consecutive integers to consecutive dates reduces elapsed-day calculations to subtraction. Converting between calendars can similarly be reduced to converting to and from a common day number (Dershowitz and Reingold 1990, pp. 900-901).

For a concrete construction, apply the Gregorian rules to every positive integer year Y. A year is a leap year iff Y is a multiple of 4 and is either not a multiple of 100 or is a multiple of 400. Let l_i(Y) be the length of month i. The lengths from January through December are 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, with February increased to 29 days in a leap year. Number January 1 of year 1 as day 1. A valid date with month m and day d then has day number

 N(Y,m,d)=365(Y-1)+|_(Y-1)/4_|-|_(Y-1)/(100)_|+|_(Y-1)/(400)_|+sum_(i=1)^(m-1)l_i(Y)+d,
(1)

where 1<=m<=12, 1<=d<=l_m(Y), and |_x_| is the floor function (Dershowitz and Reingold 1990, pp. 903-905). The combination of the three floor function terms counts leap days in preceding years. For an integer k with N+k>0, adding k days changes the day number to N+k. The inverse calculation finds the year and month containing the day number, then obtains the day by subtraction (Dershowitz and Reingold 1990, pp. 905-906).

With Sunday through Saturday encoded by 0 through 6, the weekday is mod(N,7), where mod gives the remainder from 0 through 6 and day 1 is a Monday (Dershowitz and Reingold 1990, p. 901). Thus two dates have the same weekday iff their day numbers are congruent modulo 7. The doomsday algorithm is a mental method for the weekday calculation that uses selected dates with a common weekday as anchors. For a month-day that exists in consecutive years, the weekday advances by one or two days according as the interval contains 365 or 366 days. The two-day shift occurs when the interval includes February 29. February 29 itself has no occurrence in the intervening common years.

Every block of 400 consecutive years contains 100-4+1=97 leap years, so

 N(Y+400,m,d)-N(Y,m,d)=400·365+97=146097=7·20871.
(2)

The month-length pattern therefore repeats with the same weekdays after 400 years. Among the 4800 months in a complete cycle, the numbers whose thirteenth day falls on Sunday through Saturday are 687, 685, 685, 687, 684, 688, 684 (OEIS A101944). Consequently, a month selected uniformly from the cycle has a Friday the thirteenth with probability 688/4800=43/300, slightly greater than 1/7.

The birthday problem requires an additional sampling model. If days are sampled independently and uniformly from a complete 400-year cycle, each month-day other than February 29 occurs 400 times, while February 29 occurs 97 times. The probability that two such samples have the same month and day is therefore

 P=365((400)/(146097))^2+((97)/(146097))^2.
(3)

This model gives unequal probabilities to the 366 possible month-day labels. Including February 29 therefore does not by itself justify a discrete uniform distribution on 366 birthdays.


See also

Birthday Problem, Congruence, Doomsday Algorithm, Modular Arithmetic

Explore with Wolfram|Alpha

References

Dershowitz, N. and Reingold, E. M. "Calendrical Calculations." Softw. Pract. Exper. 20, 899-928, 1990. https://doi.org/10.1002/spe.4380200905.Sloane, N. J. A. Sequence A101944 in "The On-Line Encyclopedia of Integer Sequences."

Cite this as:

Weisstein, Eric W. "Calendar Arithmetic." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/CalendarArithmetic.html

Subject classifications