Python - converting strings in an array to dates

Note to future readers: Please do not edit this answer. '"%Y-%m-%d"' is not a mistake. OP's dates are surrounded by quotes.


dates is a list of strings. So if you want to create a list of dates from its elements:

dates_list = [dt.datetime.strptime(date, '"%Y-%m-%d"').date() for date in dates]

This line iterates over the strings in the dates list and using list comprehension to create a new list of dates.


You can use split for faster result:

from datetime import datetime
today = datetime.now().strftime("%Y-%m-%d").split('-')