I would like to parse a date that can come in several formats, that I know beforehand. If I could not parse, I return nil. In ruby, I do like this:
DATE_FORM
I would just try dateutil. It can recognize most of the formats:
from dateutil import parser
parser.parse(string)
if you end up using datetime.strptime as suggested @RocketDonkey:
from datetime import datetime
def func(s,flist):
for f in flist:
try:
return datetime.strptime(s,f)
except ValueError:
pass