Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm playing with the Python datetime module. I'm using it to determine the day of the week for a given date. Python conveniently raises a ValueError when the date is invalid; e.g., for February 29 on non-leap years.

I have found that for years greater than 10,000 AD, ValueError exceptions are raised for many dates that are not February 29. This leads me to consider that the datetime module is not valid for dates that far in the future.

What is the range of valid dates for the datetime module?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

Check date.min and date.max:

>>> from datetime import date
>>> date.min
datetime.date(1, 1, 1)
>>> date.max
datetime.date(9999, 12, 31)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...