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.
- 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:
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
| Variable | Calculation | Value |
|---|---|---|
| a | INT((14 − 2) / 12) | 1 |
| y | 2026 + 4800 − 1 | 6825 |
| m | 2 + 12(1) − 3 | 11 |
| JDN | 4 + INT((153 × 11 + 2)/5) + 365 × 6825 + INT(6825/4) − INT(6825/100) + INT(6825/400) − 32045 | 2,461,412 |
Days Between Two Dates
To find the number of days between two dates, simply compute the JDN for each and subtract:
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
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 Value | Day | h Value | Day |
|---|---|---|---|
| 0 | Saturday | 4 | Wednesday |
| 1 | Sunday | 5 | Thursday |
| 2 | Monday | 6 | Friday |
| 3 | Tuesday |
Leap Year Formula
The Gregorian leap year rule can be expressed as a simple boolean formula:
Truth Table
| Condition | Divisible by 4? | Divisible by 100? | Divisible by 400? | Leap Year? |
|---|---|---|---|---|
| Regular year (e.g., 2025) | No | — | — | No |
| Leap year (e.g., 2024) | Yes | No | — | Yes |
| Century exception (e.g., 1900) | Yes | Yes | No | No |
| 400-year exception (e.g., 2000) | Yes | Yes | Yes | Yes |
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)
| Step | Formula | Description |
|---|---|---|
| 1 | a = Y mod 19 | Metonic cycle position |
| 2 | b = INT(Y / 100) | Century |
| 3 | c = Y mod 100 | Year within century |
| 4 | d = INT(b / 4) | Leap century correction |
| 5 | e = b mod 4 | Leap century remainder |
| 6 | f = INT((b + 8) / 25) | Proemptosis correction |
| 7 | g = INT((b − f + 1) / 3) | Proemptosis correction continued |
| 8 | h = (19a + b − d − g + 15) mod 30 | Paschal 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
| Date | Unix Timestamp | Significance |
|---|---|---|
| January 1, 1970 | 0 | Unix Epoch (origin) |
| February 4, 2026 | 1,770,163,200 | Today (approx. midnight UTC) |
| January 19, 2038 | 2,147,483,647 | 32-bit overflow (Y2K38 problem) |
| December 31, 2099 | 4,102,444,800 | End of century |
Converting Between Timestamps and Dates
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
| Formula | Purpose | Input | Output |
|---|---|---|---|
| Julian Day Number | Days between any two dates | Year, Month, Day | Integer day count |
| Zeller's Congruence | Day of the week | Year, Month, Day | 0-6 (Sat-Fri) |
| Leap Year Rule | Is a year a leap year? | Year | True/False |
| Gauss's Easter | Easter Sunday date | Year | Month and Day |
| Unix Timestamp | Seconds since 1970 | Date & Time | Integer (seconds) |
| Day-of-Year | Position within year | Month, Day | 1-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.