Python date.fromordinal() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
classmethod

Definition

date.fromordinal(ordinal) returns the date for a proleptic Gregorian ordinal: a day count where 1 is 0001-01-01 and each later day adds one. Day 738886 is 2024-01-01.

It is the exact inverse of toordinal(). datetime.fromordinal() does the same and returns a datetime at midnight, with tzinfo set to None.

date.fromordinal() is a classmethod of datetime.date: call it on the class itself, as date.fromordinal(...), and it returns a new object. Import the class first, for example from datetime import date. The datetime class has a method with the same name.

Syntax

Pass a whole number of days.

python
day = date.fromordinal(ordinal)
moment = datetime.fromordinal(ordinal)
CallWhat it does
date.fromordinal(1)Returns datetime.date(1, 1, 1): the first supported day.
date.fromordinal(738886)Returns datetime.date(2024, 1, 1).
datetime.fromordinal(738886)Returns datetime.datetime(2024, 1, 1, 0, 0): midnight.

Ordinals ignore time zones and times of day; they only count calendar days.

Method signatures
python
classmethod date.fromordinal(ordinal)
classmethod datetime.fromordinal(ordinal)
# ordinal: int, 1 <= ordinal <= date.max.toordinal() (3652059)

Parameters

ParameterDescription
ordinalAn int from 1 (0001-01-01) to 3652059 (9999-12-31).

Return Value

Return ValueDescription
dateThe matching calendar day (from date.fromordinal).
datetimeThe same day at 00:00:00, naive (from datetime.fromordinal).

Python Examples

Example 1 — Turn Day Numbers into Dates

Convert a few known ordinals and the day after 28 February in a leap year.

python
from datetime import date

print(date.fromordinal(1))
print(date.fromordinal(738886))
print(date.fromordinal(719163))
print(date.fromordinal(date(2024, 2, 28).toordinal() + 1))

How It Works

  1. Day one. Ordinal 1 is the first day of year 1, printed with four year digits.
  2. Recent dates. 738886 is 1 January 2024, and 719163 is the Unix epoch date.
  3. Leap day included. Adding 1 to the ordinal of 28 February 2024 lands on 29 February because 2024 is a leap year.

Example 2 — Store a Schedule as Day Numbers

Keep dates as plain ints, add day offsets, and convert back to dates and to a midnight datetime.

python
from datetime import date, datetime

start = date(2024, 3, 15).toordinal()
schedule = [start + offset for offset in (0, 14, 28)]

print(schedule)
print([date.fromordinal(n).isoformat() for n in schedule])
print(datetime.fromordinal(schedule[-1]))

How It Works

  1. Ints are easy to store. A day number fits in any integer column and sorts naturally.
  2. Plain addition. Adding 14 and 28 to the start ordinal gives the fortnightly dates.
  3. Back to dates. date.fromordinal() plus isoformat() produces readable strings.
  4. Midnight datetime. The datetime version sets the time to 00:00:00.

Example 3 — Check the Valid Ordinal Range

Find the largest ordinal and see which values raise ValueError.

python
from datetime import date

print(date.max.toordinal())
for n in (0, 3652059, 3652060):
    try:
        print(n, date.fromordinal(n))
    except ValueError:
        print(n, "is out of range")

How It Works

  1. Upper limit. date.max is 9999-12-31, and its ordinal is 3652059.
  2. No day zero. Counting starts at 1, so 0 raises ValueError.
  3. Past the end. One more than the maximum would be in year 10000, which is not supported.

Frequently Asked Questions

A day count that applies the Gregorian calendar backwards to year 1. Day 1 is 0001-01-01.
toordinal(). date.fromordinal(d.toordinal()) == d is always True.
No. It always returns midnight, and tzinfo is None.
The valid range starts at 1. Values below 1 or above 3652059 raise ValueError.
Not directly, because Excel counts from a different start. Add a fixed offset, or add timedelta(days=n) to Excel's base date.

Next: datetime.fromtimestamp()

Classmethod: turn a POSIX timestamp (seconds since 1970 UTC) into a datetime.

fromtimestamp() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful