Date Calculation Formulas – Mathematical Methods for Dates

Behind every date calculator lies a set of mathematical formulas developed over centuries by astronomers, mathematicians, and computer scientists. This guide presents the most important formulas for date arithmetic — from finding the day of the week for any date to calculating the exact number of days between dates spanning thousands of years. For quick calculations without the math, use our free date calculator.

Key Takeaways
  • Julian Day Number: Converts any date to a single integer for easy arithmetic
  • Zeller's Congruence: Determines the day of the week for any date
  • Leap Year Formula: Divisible by 4, not by 100, unless also by 400
  • Unix Timestamp: Seconds since January 1, 1970 — the foundation of computer time
  • Gauss's Algorithm: Calculates Easter Sunday for any year

Julian Day Number (JDN)

The Julian Day Number is a continuous count of days since the beginning of the Julian Period on January 1, 4713 BC (Julian calendar). It is the most reliable method for computing days between any two dates because it eliminates all month-length and leap-year complications.

The Formula

For a Gregorian calendar date with year Y, month M, and day D:

a = INT((14 − M) / 12)
y = Y + 4800 − a
m = M + 12a − 3
JDN = D + INT((153m + 2) / 5) + 365y + INT(y/4) − INT(y/100) + INT(y/400) − 32045

Example: February 4, 2026

VariableCalculationValue
aINT((14 − 2) / 12)1
y2026 + 4800 − 16825
m2 + 12(1) − 311
JDN4 + INT((153 × 11 + 2)/5) + 365 × 6825 + INT(6825/4) − INT(6825/100) + INT(6825/400) − 320452,461,412

Days Between Two Dates

To find the number of days between two dates, simply compute the JDN for each and subtract:

Days = JDN(Date2) − JDN(Date1)

Zeller's Congruence (Day of the Week)

Zeller's congruence is a formula that computes the day of the week for any Gregorian calendar date. It was devised by Christian Zeller in 1887.

The Formula

h = (q + INT(13(m+1)/5) + K + INT(K/4) + INT(J/4) − 2J) mod 7

Where:

  • q = day of the month
  • m = month (3 = March, 4 = April, ... 14 = February; January and February are treated as months 13 and 14 of the previous year)
  • K = year of the century (year mod 100)
  • J = zero-based century (INT(year / 100))
  • h = day of week (0 = Saturday, 1 = Sunday, 2 = Monday, ..., 6 = Friday)

Day of Week Mapping

h ValueDayh ValueDay
0Saturday4Wednesday
1Sunday5Thursday
2Monday6Friday
3Tuesday

Leap Year Formula

The Gregorian leap year rule can be expressed as a simple boolean formula:

isLeapYear = (Y mod 4 = 0) AND ((Y mod 100 ≠ 0) OR (Y mod 400 = 0))

Truth Table

ConditionDivisible by 4?Divisible by 100?Divisible by 400?Leap Year?
Regular year (e.g., 2025)NoNo
Leap year (e.g., 2024)YesNoYes
Century exception (e.g., 1900)YesYesNoNo
400-year exception (e.g., 2000)YesYesYesYes

This system keeps the calendar aligned with the solar year (365.2422 days). Over 400 years, there are exactly 97 leap years, giving an average year length of 365.2425 days — remarkably close to the true value.

Gauss's Easter Algorithm

Carl Friedrich Gauss published an algorithm in 1800 to calculate the date of Easter Sunday for any year. Easter is the first Sunday after the first full moon on or after the March equinox.

Simplified Steps (Gregorian Calendar)

StepFormulaDescription
1a = Y mod 19Metonic cycle position
2b = INT(Y / 100)Century
3c = Y mod 100Year within century
4d = INT(b / 4)Leap century correction
5e = b mod 4Leap century remainder
6f = INT((b + 8) / 25)Proemptosis correction
7g = INT((b − f + 1) / 3)Proemptosis correction continued
8h = (19a + b − d − g + 15) mod 30Paschal full moon offset
9-12(additional steps)Compute final Sunday date

For 2026, the algorithm yields April 5 as Easter Sunday. This algorithm is still used today in calendar software worldwide.

Unix Timestamp

The Unix timestamp (also called Epoch time or POSIX time) counts the number of seconds elapsed since January 1, 1970, 00:00:00 UTC. It is the most widely used time representation in computing.

Key Values

DateUnix TimestampSignificance
January 1, 19700Unix Epoch (origin)
February 4, 20261,770,163,200Today (approx. midnight UTC)
January 19, 20382,147,483,64732-bit overflow (Y2K38 problem)
December 31, 20994,102,444,800End of century

Converting Between Timestamps and Dates

Days since Epoch = INT(timestamp / 86400)
timestamp = Days × 86400

Since there are 86,400 seconds in a day (60 × 60 × 24), dividing a Unix timestamp by 86,400 gives you the number of days since January 1, 1970. This is the basis for how computers calculate date differences.

Summary of All Formulas

FormulaPurposeInputOutput
Julian Day NumberDays between any two datesYear, Month, DayInteger day count
Zeller's CongruenceDay of the weekYear, Month, Day0-6 (Sat-Fri)
Leap Year RuleIs a year a leap year?YearTrue/False
Gauss's EasterEaster Sunday dateYearMonth and Day
Unix TimestampSeconds since 1970Date & TimeInteger (seconds)
Day-of-YearPosition within yearMonth, Day1-365/366

Frequently Asked Questions

The Julian Day Number formula is the most accurate and general-purpose method. It correctly handles all month lengths, leap years, and century boundaries. It works for any date in the Gregorian calendar and requires only a single subtraction to find the days between two dates.

Zeller's congruence uses modular arithmetic to map any Gregorian date to a day of the week. It treats January and February as months 13 and 14 of the previous year, which simplifies the leap year correction. The result is a number from 0-6 representing Saturday through Friday.

A solar year is approximately 365.2422 days. Dividing by 4 alone gives 365.25 (too many). Removing century years (div by 100) gives 365.24 (too few). Adding back 400-year cycles gives 365.2425, which is accurate to within 1 day per 3,236 years. See our leap year guide for more detail.

The Y2K38 problem (also called the Unix Millennium Bug) occurs on January 19, 2038, when 32-bit signed integer Unix timestamps overflow. The maximum value is 2,147,483,647 (2^31 − 1), which corresponds to 03:14:07 UTC on that date. Systems using 32-bit timestamps will wrap around to negative values, potentially interpreting the date as December 13, 1901. Most modern systems now use 64-bit timestamps.

The Julian Day Number formula presented here is for the Gregorian calendar (adopted in 1582). A modified version exists for the Julian calendar used before that date. For dates spanning the transition, separate calculations are needed. Most historical date research uses the proleptic Gregorian calendar, which extends Gregorian rules backward.

Most systems store dates as either Unix timestamps (seconds since 1970), Julian Day Numbers, or serial numbers (days since a reference date like January 1, 1900 in Excel). All three approaches reduce date arithmetic to simple integer subtraction. JavaScript, for example, stores dates as milliseconds since the Unix Epoch.

Related Guides