Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

fromordinal
date module
python
communitycreator

What is date.fromordinal(ordinal) in Python?

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The fromordinal() method is used to convert a Gregorian ordinal to an equivalent Gregorian date format. It is a reverse method of toordinal() that takes a Gregorian date as an argument and returns an ordinal.

Syntax

date.fromordinal(ordinal)

Parameters

ordinal: It takes an ordinal as an argument value.

Return value

It returns the date in Gregorian calendar format.

Example

# Load datetime module
import datetime
# Random ordinal
ordinal = 2141;
# passing Gregorian ordinal to fromordinal() method
date = datetime.date.fromordinal(ordinal);

# Printing the Gregorian date
print("Date Parallel to Gregorian Ordinal %d is: %s"
                %(ordinal, date))

Explanation

  • Line 2: We import the datetime library.
  • Line 4: We declare an ordinal variable and assign a value to it.
  • Line 6: We call the date.fromordinal method.
  • Line 9: We print the Gregorian date.

RELATED TAGS

fromordinal
date module
python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring