Reputation: 145
I am trying to change string to datetime like below:
max_datetime = datetime.strptime(max_date,'%y-%m-%d %H:%M:%S')
However, I am getting the below-mentioned error:
ValueError: time data '2008-05-15 11:26:40' does not match format '%y-%m-%d %H:%M:%S'
Any help will be appreciated!
Upvotes: 0
Views: 60
Reputation: 6184
The documentation of datetime
tells that %y
(with a lowercase y) represents a two-digit year, while from the error-message we can see that your input, max_date
has a four-digit year. A four-digit year is represented by %Y
(with an uppercase Y). So this is the source of your error. Since the rest looks fine,
max_datetime = datetime.strptime(max_date, "%Y-%m-%d %H:%M:%S")
should do the job.
Upvotes: 2