How to convert a Python date string to a date object?
Answers
Answered by
0
You can convert a string to date object using the strptime function. Provide the date string and the format in which the date is specified. For example,
import datetime
date_str = '29122017' # The date - 29 Dec 2017
format_str = '%d%m%Y' # The format
datetime_obj = datetime.datetime.strptime(date_str, format_str)
print(datetime_obj.date())
This will give the output:
Similar questions