The Problem
I am working on a python application that analyzes user input, and attempts to work out how to regenerate it. Part of this is ingesting dates / times / datetimes of arbitrary formats as strings, and detecting what the format is.
Example
- Given an input date of
23-09-1992
, I should be able to produce the format%d-%m-%Y
- Given an input time of
13:09
, I should be able to produce the format%h:%m
Ideally this should work generically, so I can provide any common date, time or datetime string and it will deduce the format for me.
My Attempts
I attempted to build a list of known datetime / date / time formats but quickly realised I could be here until I die, so decided against it.
I have reached into the code of
dateutils.parser
to see if something in there can help, but I don't think it can. It does not look like a format is generated, rather thedatetime
object is built directly.