code: def DateStringToDateObject(date_string):
    
    # If this becomes a bottleneck date objects could be cached
    if re.match('^\d{8}$', date_string) == None:
      return None
    try:
      return datetime.date(int(date_string[0:4]), int(date_string[4:6]),
                           int(date_string[6:8]))
    except ValueError:
      return None
docs: Return a date object for a string "YYYYMMDD".