## Date Algorithms

By Peter Baum
Onset, MA 02558-1255

Version: 1.003

The information contained in the sections listed below is a guide to computer programmers interested in implementing date algorithms in a variety of languages and on a wide range of hardware platforms. Although all rights are reserved under the copyright laws, programmers may implement the algorithms without permission. However, I would ask that if this is done for any of the algorithms that are not known to be fully documented elsewhere, a reference be made to this document. Doing so will assure full and consistent documentation, minimize the propagation of any errors that might be discovered, and provide a central location for any improvements that are made in the future.

Various calendar dates (Julian, Gregorian, and Rata Die) are used and produced by the algorithms that are presented but no attempt has been made to account for various problems associated with the general use of historical dates. For example, 90 days were inserted into the calendar by Julius Caesar in -45 and following Caesar's death, the leap year rule was misapplied until corrected by Emperor Augustus who omitted leap years from years -8 through +4. Various locations used different calendars throughout the Middle Ages and even within one locality, different calendars were often used for dating ecclesiastical records, fiscal transactions, and personal correspondence. None of these complications are accounted for by these algorithms. The following is assumed:

• The year before the year 1 is 0 and the year before 0 is -1, et cetera. The year 0 corresponds to 1 B.C.
• Julian dates may be applied both before the calendar was invented and after it was replaced as long as it is clear that the Julian leap year rules are being applied, usually by calling the date a Julian date.
• Gregorian dates may be applied before the Gregorian calendar was invented as long as it is clear that the Gregorian calendar leap year rules are being applied, usually by calling it a Gregorian date.
1. Calendars and Dates - Definitions and general information.
2. Converting a Gregorian or Julian date to its corresponding Julian Day Number.
3. Converting a Julian Day Number to its corresponding Gregorian or Julian date.
4. Modified Julian Day (MJD)
5. Rata Die
6. Inverse Rata Die
7. Day of the Week
8. Difference between dates