string to date python

from datetime import datetime

# Assuming the string follows the format 'YYYY-MM-DD'
date_string = "2023-12-31"
date_object = datetime.strptime(date_string, '%Y-%m-%d')

print(date_object)