I am converting date strings to datetime objects for comparison using datetime.strptime('00:01:47.210', '%H:%M:%S.%f'). Now the problem is that I encountered a datetime string which did not have milliseconds 0:01:53, and I got an error saying ValueError: time data '0:01:53' does not match format '%H:%M:%S.%f'. How do I handle multiple datetime string formats? Specifically, how do I convert datetime strings with and without missing milliseconds.
Asked
Active
Viewed 39 times
0
Aditya
- 906
- 9
- 29
-
[Related](https://stackoverflow.com/questions/30584364/python-strptime-format-with-optional-bits) – Cory Kramer Oct 12 '21 at 11:54