I'm converting a date string using the following (not the full code, just the relevant bit):
str_format = '%Y-%m-%d %H:%M:%S'
datetime.strptime('2015-13-23 13:43:23', str_format)
This throws a "time data does not match format" because the month is wrong (13 is not a valid month).
I was wondering if it was possible to have it raise an exception on the month (or day) being invalid instead of the format not matching because of the invalid date? The following clearly shows that datetime can determine that:
>>> print datetime(2015, 13, 23)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: month must be in 1..12