import datetime date = '2021-01-01' # For a datetime.datetime obj: datetime.datetime.strptime(date, '%Y-%m-%d') # For a datetime.date obj: datetime.datetime.strptime(date, '%Y-%m-%d').date()