def couch_to_excel_datetime(val, doc):
    if isinstance(val, basestring):
        # todo: subtree merge couchexport into commcare-hq
        # todo: and replace this with iso_string_to_datetime
        dt_val = None
        for fmt in COUCH_FORMATS:
            try:
                dt_val = datetime.datetime.strptime(val, fmt)
            except ValueError:
                pass
            else:
                break
        if dt_val is not None:
            try:
                return dt_val.strftime(EXCEL_FORMAT)
            except __HOLE__:
                pass
    return val
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/couchexport/transforms.py/couch_to_excel_datetime