def sniff_date(datestr):
 dateformats = ('%Y%m%d', '%Y-%m-%d', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT', '%Y/%m/%d')
 for dfmt in dateformats:
  try:
   return datetime.datetime.strptime(datestr.strip(), dfmt)
  except (ValueError, AttributeError):
   return datetime.datetime.utcnow()

def sniff_date ( datestr ) : dateformats = ( '%Y%m%d' , '%Y-%m-%d' , '%Y-%m-%dT%H:%M:%SZ' , '%Y-%m-%dT' , '%Y/%m/%d' ) for dfmt in dateformats : try : return datetime . datetime . strptime ( datestr . strip ( ) , dfmt ) except ( ValueError , AttributeError ) : return datetime . datetime . utcnow ( )
attempt to parse date into datetime .