Last verified · v1.0
Calculator · general
Day Of The Year Calculator
Convert any calendar date to its ordinal day number (1-366) instantly. Supports all years with automatic leap year detection.
Inputs
Day of Year
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
The formula
How the
result is
computed.
What Is the Day of the Year?
The day of the year (DOY), also called the ordinal date, is a number from 1 to 366 representing a date's sequential position within a calendar year. January 1 is always DOY 1; December 31 is DOY 365 in a standard year or 366 in a leap year. This single integer simplifies date arithmetic and appears across astronomy, meteorology, agricultural scheduling, financial modeling, and software development.
The Day of the Year Formula
The standard formula computes DOY as:
DOY = Σi=1m−1 di + d + δleap(m)
where:
- m — target month (1 = January through 12 = December)
- d — day of the month (1–31)
- di — number of days in month i in a standard non-leap year
- δleap(m) — correction term equal to 1 if the year is a leap year and m > 2; otherwise 0
Step-by-Step Derivation
The formula proceeds in three stages:
- Sum all months before the target. Add the standard day counts of every month from January through the month immediately before the target month. For March (m = 3): 31 days (January) + 28 days (February) = 59.
- Add the day of the month. Append value d directly to the running total. March 15 gives 59 + 15 = 74.
- Apply the leap-year correction. If the year is a leap year and m > 2, add 1. March 15 in 2024 (a leap year): 74 + 1 = 75.
Cumulative Days Before Each Month (Non-Leap Year)
The values below represent the sum of days in all preceding months, anchoring each month's DOY range:
- January: 0 prior days — DOY range 1–31
- February: 31 prior days — DOY range 32–59
- March: 59 prior days — DOY range 60–90
- April: 90 prior days — DOY range 91–120
- May: 120 prior days — DOY range 121–151
- June: 151 prior days — DOY range 152–181
- July: 181 prior days — DOY range 182–212
- August: 212 prior days — DOY range 213–243
- September: 243 prior days — DOY range 244–273
- October: 273 prior days — DOY range 274–304
- November: 304 prior days — DOY range 305–334
- December: 334 prior days — DOY range 335–365
Leap Year Identification
A year qualifies as a leap year when it is divisible by 4, except for century years, which must also be divisible by 400. Therefore 2000 was a leap year; 1900 was not. According to NASA JPL Education's Leap Day Math, this rule keeps the Gregorian calendar within one day of Earth's 365.2422-day solar year across a span of 3,300 years. The correction term adds 1 only for March onward because February absorbs the extra day.
Worked Examples
Example 1: Independence Day — July 4, 2023
Prior months (Jan–Jun, non-leap): 31+28+31+30+31+30 = 181. Add day 4: 181 + 4 = 185. Year 2023 is not a leap year (δ = 0). DOY = 185.
Example 2: Pi Day — March 14, 2024 (Leap Year)
Prior months (Jan–Feb, non-leap): 31+28 = 59. Add day 14: 59 + 14 = 73. Year 2024 is a leap year and m = 3 > 2, so δ = 1. DOY = 74.
Example 3: New Year's Eve — December 31, 2024 (Leap Year)
Prior months (Jan–Nov, non-leap sum): 334. Add day 31: 334 + 31 = 365. Year 2024 is a leap year and m = 12 > 2, so δ = 1. DOY = 366.
Practical Applications
The DOY integer drives solar declination equations used by the NOAA Global Monitoring Laboratory's Solar Calculation Details, which compute sunrise, sunset, and hourly irradiance based on DOY. Agronomists use DOY to track growing degree days; epidemiologists index seasonal disease data to DOY for year-over-year trend comparisons; pilots reference DOY in magnetic declination tables; and software developers reduce multi-field date comparisons to single integer subtractions.
Methodology and Sources
This calculator implements the arithmetic calendar method documented by NASA Glenn Research Center's Calendar Calculations guide and cross-validated against the day-counting approach in the WPI Happy Birthday mathematical paper. Both sources confirm the standard month-accumulation algorithm with the Gregorian leap-year correction term δleap.
Reference