{"record":{"id":"bc0c1757e950f6f3","repo":"go-gorm/gorm","slug":"failed-to-set-string-v-to-time-time-field-s-fai","errorCode":null,"errorMessage":"failed to set string %v to time.Time field %s, failed to parse it as time, got error %v","messagePattern":"failed to set string (.+?) to time\\.Time field (.+?), failed to parse it as time, got error (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/field.go","lineNumber":854,"sourceCode":"\t\t\tfield.Set = func(ctx context.Context, value reflect.Value, v interface{}) error {\n\t\t\t\tswitch data := v.(type) {\n\t\t\t\tcase **time.Time:\n\t\t\t\t\tif data != nil && *data != nil {\n\t\t\t\t\t\tfield.Set(ctx, value, *data)\n\t\t\t\t\t}\n\t\t\t\tcase time.Time:\n\t\t\t\t\tfield.ReflectValueOf(ctx, value).Set(reflect.ValueOf(v))\n\t\t\t\tcase *time.Time:\n\t\t\t\t\tif data != nil {\n\t\t\t\t\t\tfield.ReflectValueOf(ctx, value).Set(reflect.ValueOf(data).Elem())\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfield.ReflectValueOf(ctx, value).Set(reflect.ValueOf(time.Time{}))\n\t\t\t\t\t}\n\t\t\t\tcase string:\n\t\t\t\t\tif t, err := now.Parse(data); err == nil {\n\t\t\t\t\t\tfield.ReflectValueOf(ctx, value).Set(reflect.ValueOf(t))\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn fmt.Errorf(\"failed to set string %v to time.Time field %s, failed to parse it as time, got error %v\", v, field.Name, err)\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn fallbackSetter(ctx, value, v, field.Set)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t}\n\t\tcase *time.Time:\n\t\t\tfield.Set = func(ctx context.Context, value reflect.Value, v interface{}) error {\n\t\t\t\tswitch data := v.(type) {\n\t\t\t\tcase **time.Time:\n\t\t\t\t\tif data != nil && *data != nil {\n\t\t\t\t\t\tfield.ReflectValueOf(ctx, value).Set(reflect.ValueOf(*data))\n\t\t\t\t\t}\n\t\t\t\tcase time.Time:\n\t\t\t\t\tfieldValue := field.ReflectValueOf(ctx, value)\n\t\t\t\t\tif fieldValue.IsNil() {\n\t\t\t\t\t\tfieldValue.Set(reflect.New(field.FieldType.Elem()))\n\t\t\t\t\t}","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/schema/field.go#L836-L872","documentation":"Error \"failed to set string %v to time.Time field %s, failed to parse it as time, got error %v\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at schema/field.go:854 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Format the time string in a layout GORM recognizes (e.g. RFC3339 or the configured time format).","Parse the string into time.Time before assigning it to the field.","Check NowFunc / serializer configuration for custom time handling."],"exampleFix":"Set time fields with time.Time values or strings in a parseable layout, or configure NowFunc/parse format accordingly.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}