I have a variable containing a string from which I want to parse the date. I tryed this:
import datetime
date_string = "July 2010"
parsed_date = datetime.datetime.strptime(date_string, "%B %Y")
print parsed_date
# datetime.datetime(2010, 7, 1, 0, 0))
I assume the 1 is added by datetime, because a date must have a day?
But why are there two zeroes? I assume this shall be the time? Is there a way to avoid the time? I only want the date.
Simply call
.date()on the datetime object. This returns adateobject.For your other subquestions:
0, 0is the time.1 <= day <= 31).