How do you take a date, formatted randomly, and figure out what that format is?
I'm reading columns in files, and one of them is a date. However, there are many different formats I encounter: here are examples.
strdate = ["6/4/2014 12:55:36 AM", "2014-06-04 6:27:55 PM"], etc.
The best (fastest) way to parse the date appears to be dateutil.parser.parse()
. However, I ALSO want to know the format of the string read in each file, so next time I encounter a date in a similar file, I don't have to use parse()
. This should all be automatic; the file is read, a date pops out, and the format is saved so the next time a similar file is read, I can use datetime
with a specified format.
How do you retrieve the format of a date?