toordinal() Function Of Datetime.date Class In Python
The toordinal() function is used to return the proleptic Gregorian ordinal of a specified datetime instance.
Note: The Proleptic Gregorian ordinal gives the number of days elapsed from the date 01/Jan/0001. And here ordinal is called Proleptic since the Gregorian calendar itself is followed from October 1582.
Syntax: toordinal()
Parameters: This function does not accept any parameter.
Return values: This function returns the proleptic Gregorian ordinal of a datetime instance.
Example 1: Using today’s date.
Python3
import datetime
import time
todays_Date = datetime.date.fromtimestamp(time.time());
date = todays_Date.toordinal();
print ( "Proleptic Ordinal for today's date: %s" % date);
|
Output:
Proleptic Ordinal for today's date: 737998
Example 2: Using today’s date and time.
Python3
import datetime
import time
todays_DateTime = datetime.datetime.now();
DateTime = todays_DateTime.toordinal();
print ( "Proleptic Ordinal for today's date and time: %s" % DateTime);
|
Output:
Proleptic Ordinal for today's date and time: 737998
Example 3: Using a specific date.
Python3
import datetime
import time
DateTime = datetime.datetime( 1358 , 8 , 12 , 1 , 3 , 4 , 9 );
Date_Time = DateTime.toordinal();
print ( "Proleptic Ordinal for today's date and time: %s" % Date_Time);
|
Output:
Proleptic Ordinal for today's date and time: 495858
Last Updated :
23 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...