Date Algorithms

By Peter Baum
Onset, MA 02558-1255
©1998, Peter Baum

Version: 1.003
Last Modified: August 5, 1998

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:

  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