toordinal : Return Proleptic Gregorian ordinal of the date starting with 1 as January 1 of year 1.
« How ordinal is used to get date by using fromordinal()
Today's ordinal vlaue
from datetime import date
my_ordinal=date.today().toordinal()
print("Today toordinal value : ",my_ordinal)
Output
Today toordinal value : 737319
Getting todays and tomorrows toordinal. We used timedelta here to get tomorrow's date object.
from datetime import date,datetime, timedelta
print("Today toordinal : ",date.today().today().toordinal())
tomorrow=date.today() + timedelta(days=1)
print("Tomorrow toordinal : ",tomorrow.toordinal())
Output is here
Today toordinal : 737319
Tomorrow toordinal : 737320
We can create a date object and then get the value
import datetime
dt=datetime.datetime(2019,5,24) # Year , Month , date as input
print(dt.toordinal())
Output
737203
We can check the above data ( todays date )
dt=datetime.datetime(2019,9,16) # Year , Month , date as input
print(dt.toordinal())
Output
737318
« All Date Objects
← Subscribe to our YouTube Channel here