Open In App

toordinal() Function Of Datetime.date Class In Python

Last Updated : 23 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance

# importing datetime and time module
import datetime
import time

# Getting today's date
todays_Date = datetime.date.fromtimestamp(time.time());

# Calling the toordinal() function over the
# today's date
date = todays_Date.toordinal();

# Printing the proleptic Gregorian ordinal
# for the today's date
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
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance

# importing datetime and time module
import datetime
import time

# Getting today's date and time
todays_DateTime = datetime.datetime.now();

# Calling the toordinal() function over the
# today's date and time
DateTime = todays_DateTime.toordinal();

# Printing the proleptic Gregorian ordinal
# for the today's date and time
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
# Python3 code to demonstrate
# Getting the proleptic Gregorian
# ordinal of a datetime instance

# importing datetime and time module
import datetime
import time

# Initializing a date and time
DateTime = datetime.datetime(1358, 8, 12, 1, 3, 4, 9);

# Calling the toordinal() function over the
# above date and time
Date_Time = DateTime.toordinal();

# Printing the proleptic Gregorian ordinal
# for the above given date and time
print("Proleptic Ordinal for today's date and time: %s"%Date_Time);

Output:

Proleptic Ordinal for today's date and time: 495858

Next Article
Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy