terican

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.

FreeInstantNo signupOpen source

Inputs

Day of Year

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Day of Year

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:

  1. 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.
  2. Add the day of the month. Append value d directly to the running total. March 15 gives 59 + 15 = 74.
  3. 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

Frequently asked questions

What is a day of the year calculator used for?
A day of the year calculator converts a standard calendar date into an ordinal date — a single integer from 1 to 366. Scientists, engineers, and developers rely on this number for solar angle computations, agricultural scheduling, epidemiological trend analysis, and date arithmetic in programming, because a single integer is far simpler to compare or subtract than a three-field calendar date.
How does a leap year change the day of the year result?
In a leap year, February gains one extra day (29 instead of 28), shifting every date from March 1 onward forward by one position. For example, March 1 is DOY 60 in a standard year but DOY 61 in a leap year such as 2024. The formula accounts for this by adding a correction term of 1 whenever the year is a leap year and the target month is March or later.
What is the formula for calculating the day of the year?
The formula sums the standard day counts of all months before the target month, adds the target day of the month, then adds 1 if the year is a leap year and the month is March or later. For July 4, 2023, the sum of January through June equals 181, plus day 4 gives DOY 185. No leap correction applies because 2023 is not a leap year.
What is the highest possible day of the year number?
The maximum day of the year is 366, occurring only on December 31 of a leap year. In a standard 365-day year, December 31 is always DOY 365. Leap years — years divisible by 4, excluding century years not divisible by 400 — add February 29 to extend the calendar to 366 total days. The next leap years after 2024 are 2028, 2032, and 2036.
How do I convert a day of the year number back to a calendar date?
To reverse the calculation, subtract each month's day count from the DOY sequentially until the remainder fits within the current month. For DOY 200 in a non-leap year: subtract January (31) leaves 169, February (28) leaves 141, March (31) leaves 110, April (30) leaves 80, May (31) leaves 49, June (30) leaves 19. The remainder 19 falls in July, making DOY 200 equal to July 19. In a leap year, count February as 29 days.
Why do meteorologists and solar engineers use the day of the year?
The day of the year directly drives solar declination calculations. NOAA's Global Monitoring Laboratory uses DOY to compute the sun's angle above the horizon, sunrise and sunset times, and daily solar irradiance — all of which vary continuously throughout the year. Meteorologists also index seasonal temperature anomalies and historical precipitation averages to DOY, enabling straightforward year-over-year weather comparisons without converting between calendar systems.