datetime.toordinal
datetime.toordinal(…) returns the number of days since December 31, 1 BC at 00:00 in the proleptic Gregorian date:
import datetime
print(datetime.datetime.strptime('0001-01-01', '%Y-%m-%d').toordinal()) # 1
print(datetime.datetime.strptime('1582-10-04', '%Y-%m-%d').toordinal()) # 577725
print(datetime.datetime.strptime('1582-10-05', '%Y-%m-%d').toordinal()) # 577726 - inexisting date
print(datetime.datetime.strptime('1582-10-06', '%Y-%m-%d').toordinal()) # 577727 - inexisting date
print(datetime.datetime.strptime('1582-10-15', '%Y-%m-%d').toordinal()) # 577736 - 1st gregorian day
Calculating the Julian Day Number
The following snippet can be used to calculate the
Julian Day:
import datetime
import sqlite3
print ( datetime.date(2025,10,27).toordinal()+1721424.5 )
#
# Verify with with sqlite3 julianday function:
#
print (sqlite3.connect(':memory:').cursor().execute("select julianday('2025-10-27')").fetchone()[0])