Function Name
toordinal
Function Signature
toordinal()
Function Overview
- The function toordinal() returns the proleptic Gregorian ordinal of a date.
- In simple terms datetime.toordinal() returns the day count from the date 01/01/01
- Though Gregorian calendar was not followed before October 1582, several computer systems follow the Gregorian calendar for the dates that comes even before October 1582. Python's date class also does the same.
Example
import datetime
# Create a date object for George Washington's birthday
WashingtonsBirthDay = datetime.date(1732, 2, 22)
# Print Washington's BirthDay
print("George Washington's birthday is {}".format(WashingtonsBirthDay))
# Get the proleptic Gregorian ordinal for George Washington's birthday
gregorianOrdinal = WashingtonsBirthDay.toordinal()
print("George Washington was born on {}th day if you count from 01/01/01".format(gregorianOrdinal))Output
George Washington's birthday is 1732-02-22
George Washington was born on 632287th day if you count from 01/01/01