fromordinal():

fromordinal : Return date by using Proleptic Gregorian ordinal .

About ordinal by using toordinal()

Today's fromordinal vlaue

from  datetime import date
my_ordinal=date.today().toordinal()
print("Today toordinal value : ",my_ordinal)
print("Today date :",date.fromordinal(my_ordinal))
Output
Today toordinal value :  737319
Today date : 2019-09-17
Using today and tomorrow ordinal vlaue
from datetime import date,datetime,timedelta
from datetime import date
my_today=date.today().toordinal()
print("Today toordinal output : ",my_today)
my_tomorrow=date.today() + timedelta(days=1)
my_tomorrow=my_tomorrow.toordinal()
print("Tomorrow toordinal output : ",my_tomorrow)

print(date.fromordinal(my_today))
print(date.fromordinal(my_tomorrow))
Output
Today toordinal :  737319
Tomorrow toordinal :  737320
2019-09-17
2019-09-18

Example 1: Convert a Past Ordinal to Date

from datetime import date
past_ordinal = 730000
print(date.fromordinal(past_ordinal))  # Output: 1999-03-05

Example 2: Convert Future Ordinal to Date

future_ordinal = 800000
print(date.fromordinal(future_ordinal))  # Output: 2191-04-29

Example 3: Convert Today's Date to Ordinal and Back

from datetime import date
today = date.today()
ordinal_value = today.toordinal()  # Convert today's date to ordinal
print(date.fromordinal(ordinal_value))  # Output: Current date

Example 4: Handling Very Large Ordinals

large_ordinal = 1000000
print(date.fromordinal(large_ordinal))  # Output: 2738-11-28

Example 5: Converting Year 1, Day 1

first_ordinal = 1
print(date.fromordinal(first_ordinal))  # Output: 0001-01-01
All Date Objects
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer