I am using the strptime() function successfully in many cases however I could not make it work with days that have the th, nd, or other day suffix such as 'September 20th, 2019' and the cases shown in the code below. Is there a way to tell the strptime() function to ignore these two characters?
When I run the code below I am getting (no surprise) the following error:
ValueError: time data 'September 20th, 2019' does not match format '%B %d, %Y'
from datetime import datetime;
currentYear = str(datetime.now().year)
dates_array = ['September 20th, 2019','September 21st, 2019','May 3rd, 2019']
dates_array = [datetime.strptime(d, '%B %d, %Y').strftime('%m/%d/%Y') for d in dates_array]
print (dates_array)