Reputation: 22440
How can I make 8-12
to be displayed as 12-August
. I tried the following but somewhere I'm going wrong that is why I'm getting an error.
Tried like:
import datetime
dt = datetime.datetime.strptime("8-12", '%d-%b').strftime('%b-%d')
print(dt)
Output I'm expecting:
12-August
Error I'm having:
File "C:\Users\WCS\AppData\Local\Programs\Python\Python36-32\lib\_strptime.py", line 362, in _strptime
(data_string, format))
ValueError: time data '8-12' does not match format '%d-%b'
Upvotes: 0
Views: 31
Reputation: 26039
This should work:
import datetime
dt = datetime.datetime.strptime("8-12", '%m-%d').strftime('%d-%B')
print(dt)
# 12-August
Upvotes: 3