user3579609
user3579609

Reputation: 11

datetime.strptime() conversion failure for year 10000

The below python code worked fine until 12-31-9999.

It threw error once I changed the date to 01-01-10000 (see the screen shot attached)

from datetime import datetime
import time
 
          
myNewDate = "12-31-9999"
            
myNewDateTime = datetime.strptime(myNewDate, '%m-%d-%Y').date()
print (myNewDateTime)

Here is the screen shot:

enter image description here

Upvotes: 1

Views: 708

Answers (2)

Bharel
Bharel

Reputation: 26954

According to the docs, only 4 digit years are supported.

The years are limited by the 1989 C standard.

Upvotes: 3

Andrew Morozko
Andrew Morozko

Reputation: 2816

%Y signifies a 4 digit year, the last 0 is unmatched by the pattern. You can't use python datetime to work with years beyond 9999: https://docs.python.org/3/library/datetime.html#datetime.MAXYEAR

Upvotes: 1

Related Questions