Let's say I have a string: "10/12/13" and "10/15/13", how can I convert them into date objects so that I can compare the dates? For example to see which date is before or after.
Use datetime.datetime.strptime:
datetime.datetime.strptime
>>> from datetime import datetime as dt >>> a = dt.strptime("10/12/13", "%m/%d/%y") >>> b = dt.strptime("10/15/13", "%m/%d/%y") >>> a > b False >>> a < b True >>>
1.4m articles
1.4m replys
5 comments
57.0k users