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
>>> import datetime >>> datetime.datetime.strptime('24052010', "%d%m%Y").date() datetime.date(2010, 5, 24)
This is my code: import datetime today = datetime.date.today() print(today) This prints: 2008-11-22 which is exactly what I want. But, I have a list I'm appending this to and then suddenly everything goes "wonky". Here is the …
I have a Python datetime.datetime object. What is the best way to subtract one day?
If I have two dates (ex. '8/18/2008' and '9/26/2008'), what is the best way to get the number of days between these two dates?