Skip to content
πŸ› οΈToolsShed

Day of Year Calculator

Find what day number (1–365) a date falls on, or convert a day number back to a date.

About this tool

A Day of Year Calculator helps you determine which day of the year (1 through 365, or 366 in leap years) a specific date falls on. This simple but powerful tool is useful for scientists, planners, and anyone who works with date sequences, seasonal data, or astronomical calculations. By understanding which day number a date represents, you can quickly perform relative date calculations, track elapsed time, or identify seasonal events based on their position in the year.

To use the calculator, enter a calendar date and the tool instantly converts it to its day-of-year number. Alternatively, if you know the day number and want to find the corresponding calendar date, simply enter the day number and year, and the tool returns the exact date. The calculator automatically accounts for leap years, ensuring accurate results whether you're working with February 29th or any other date.

Frequently Asked Questions

Code Implementation

from datetime import date, timedelta

def day_of_year(year: int, month: int, day: int) -> int:
    """Return the ordinal day of year (1-365/366)."""
    return date(year, month, day).timetuple().tm_yday

def is_leap_year(year: int) -> bool:
    return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

def days_in_year(year: int) -> int:
    return 366 if is_leap_year(year) else 365

def iso_week_number(year: int, month: int, day: int) -> int:
    return date(year, month, day).isocalendar()[1]

def day_number_to_date(year: int, day_num: int):
    """Convert ordinal day number back to a date."""
    return date(year, 1, 1) + timedelta(days=day_num - 1)

def year_progress(year: int, month: int, day: int) -> float:
    day_num = day_of_year(year, month, day)
    total = days_in_year(year)
    return round(day_num / total * 100, 1)

# Examples
today = date.today()
y, m, d = today.year, today.month, today.day
print(f"Day of year: {day_of_year(y, m, d)}")
print(f"Week number: {iso_week_number(y, m, d)}")
print(f"Leap year: {is_leap_year(y)}")
print(f"Year progress: {year_progress(y, m, d)}%")
print(f"Day 100 of {y}: {day_number_to_date(y, 100)}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.