I need to parse a string into a datetime
with python, for example:
datetime.datetime.strptime('2018-06-29 08:15:27.243860', '%Y-%m-%d %H:%M:%S.%f')
But sometime I didn't know if the input is 2018-06-29 08:15:27.243860
or 2018-06-29 08:15:27
(without milliseconds).
If I tried
datetime.datetime.strptime('2018-06-29 08:15:27', '%Y-%m-%d %H:%M:%S.%f')
I got an exception
ValueError: time data '2018-06-29 08:15:27' does not match format '%Y-%m-%d %H:%M:%S.%f'
Is there any way to use same format to '2018-06-29 08:15:27.243860' and '2018-06-29 08:15:27'
?
I don't care about milliseconds, I want to drop them.