Python date.toordinal() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
date method

Definition

toordinal() returns the proleptic Gregorian ordinal of the date: day 1 is 0001-01-01, day 2 is 0001-01-02, and so on. 2024-01-01 is day 738886.

On a datetime it ignores the time and the zone and numbers only the date part. fromordinal() turns the number back into a date.

date.toordinal() is an instance method of datetime.date: call it on an existing object with dot notation, such as day.toordinal(...). Import the class first, for example from datetime import date. The datetime class has a method with the same name.

Syntax

Call it with no arguments.

python
number = day.toordinal()
CallWhat it does
date(1, 1, 1).toordinal()Returns 1.
date(2024, 1, 1).toordinal()Returns 738886.
date(1970, 1, 1).toordinal()Returns 719163: the Unix epoch day.

Ordinals are plain ints, so you can store them compactly, sort them, and subtract them.

Method signatures
python
date.toordinal()
datetime.toordinal()
# returns: int, 1 .. 3652059

Parameters

toordinal() takes no parameters.

Return Value

Return ValueDescription
intThe day number, from 1 for 0001-01-01 to 3652059 for 9999-12-31.

Python Examples

Example 1 — Get the Day Number of a Date

Number the first supported day, New Year 2024, and a datetime late on the same day.

python
from datetime import date, datetime

print(date(1, 1, 1).toordinal())
print(date(2024, 1, 1).toordinal())
print(datetime(2024, 1, 1, 23, 59).toordinal())

How It Works

  1. Counting starts at 1. The very first date in the calendar is day 1.
  2. Large but exact. 2024-01-01 is 738886 days into the count.
  3. Time ignored. A datetime at 23:59 on the same day gets the same ordinal.

Example 2 — Count Days Between Two Dates

Subtract ordinals and compare with date subtraction. February has 29 days in 2024 and 28 in 2023.

python
from datetime import date

start = date(2024, 2, 1)
end = date(2024, 3, 1)
print(end.toordinal() - start.toordinal())
print((end - start).days)
print(date(2023, 3, 1).toordinal() - date(2023, 2, 1).toordinal())

How It Works

  1. Ordinal subtraction. The difference of two ordinals is the number of days between them.
  2. Same as timedelta. (end - start).days gives the identical count.
  3. Leap years handled. February 2023 has 28 days, February 2024 has 29.

Example 3 — Derive the Weekday from the Ordinal

Day 1 was a Monday, so the ordinal modulo 7 encodes the weekday.

python
from datetime import date

day = date(2024, 3, 15)
n = day.toordinal()
print(n)
print(n % 7, day.isoweekday() % 7)
print((n + 6) % 7 == day.weekday())

How It Works

  1. Monday start. Ordinal 1 was a Monday, so n % 7 matches isoweekday() % 7 (Sunday becomes 0).
  2. Friday check. 738960 leaves remainder 5, and Friday's ISO number is 5.
  3. weekday() formula. (n + 6) % 7 is exactly how weekday() is defined.

Frequently Asked Questions

It turns a date into a simple day count, which is easy to store, compare, and subtract.
719163.
Use date.fromordinal(n).
No. Only the date part is counted.
No. It counts days from year 1; a timestamp counts seconds from 1970. Day number minus 719163 gives days since the epoch.

Next: timedelta.total_seconds()

Return the whole length of a timedelta in seconds, as a float.

total_seconds() →

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.

11 people found this page helpful