def convert(value, row):
    key = key_as_str(value)
    
    if not key:
        row['cdispyr'], row['cdispmo'], row['cdispda'] = 9999, 99, 99
        return value
    
    try:    
        v = key.replace('-', '')
        assert(len(v) == 8)
        assert(1850 <= int(value[:4]) <= date.today().year)
        dt = strptime(v, '%Y%m%d')
        row['cdispyr'], row['cdispmo'], row['cdispda'] = dt[0], dt[1], dt[2]
        
    except (AssertionError, ValueError):
        row['cdispyr'], row['cdispmo'], row['cdispda'] = 9999, 99, 99
        log.write('cdispdt', [row['id'], row['rapstatex'], value, "Bad date value"])
                
    return value