Back
How do I convert a string to a date object in python?
The string would be: "24052010" (corresponding to the format: "%d%m%Y")
"24052010"
"%d%m%Y"
I don't want a datetime.datetime object, but rather a datetime.date.
You can use strptime in the datetime package of Python:
strptime
datetime
>>> datetime.datetime.strptime('24052010', "%d%m%Y").date()datetime.date(2010, 5, 24)
>>> datetime.datetime.strptime('24052010', "%d%m%Y").date()
datetime.date(2010, 5, 24)
31k questions
32.4k answers
501 comments
693 users