3 ms·
No need to, already included (though I'm not so familiar with the datetime module, so I had to look for it): datetime.datetime.strptime("Aug 18 2015", "%b
by dr_zoidberg 10y ago
No need to, already included (though I'm not so familiar with the datetime module, so I had to look for it):
datetime.datetime.strptime("Aug 18 2015", "%b %d %Y")
> datetime.datetime(2015, 8, 18, 0, 0)
Like xapata said, if you import from datetime, it looks "nicer". I prefer to see where things come from most of the time, because I keep open long sessions and it can become messy otherwise.
I don't really see how this can take 10 minutes to setup. You can have the import already in a file called dateutils.py and you only set it up once:
import datetime
def string2date(val):
return datetime.datetime.strptime(val, "%b %d %Y")
Then your session becomes easier
from dateutils import *
string2date("Jul 4 1776")
datetime.datetime(1776, 7, 4, 0, 0)
However, I think at this point we're talking more about our personal preferences for tools rather than the original subject. It just struck me that your example was something that is available in Python using standard library modules.
- dr_zoidberg 10y agoA coworker noted that dateparser[0] is a strong module for this use case. [0] https://pypi.python.org/pypi/dateparser https://pypi.python.org/pypi/dateparser