I have an str variable named day and I want to convert it to date
day = "09FEB2017"
Use the appropriates format codes
day = "09FEB2017"
d = datetime.strptime(day, "%d%b%Y")
print(d) # 2017-02-09 00:00:00
print(d.date()) # 2017-02-09
from datetime import datetime
day = "09FEB2017"
datetime_object = datetime.strptime(day, '%d%b%Y')
does the trick.
Already answered here. https://stackoverflow.com/a/466376/7539615
datetime.strptime
will come in handy