go-gorm/gorm · error

failed to set string %v to time.Time field %s, failed to par

Error message

failed to set string %v to time.Time field %s, failed to parse it as time, got error %v

What it means

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.

Source

Thrown at schema/field.go:854

			field.Set = func(ctx context.Context, value reflect.Value, v interface{}) error {
				switch data := v.(type) {
				case **time.Time:
					if data != nil && *data != nil {
						field.Set(ctx, value, *data)
					}
				case time.Time:
					field.ReflectValueOf(ctx, value).Set(reflect.ValueOf(v))
				case *time.Time:
					if data != nil {
						field.ReflectValueOf(ctx, value).Set(reflect.ValueOf(data).Elem())
					} else {
						field.ReflectValueOf(ctx, value).Set(reflect.ValueOf(time.Time{}))
					}
				case string:
					if t, err := now.Parse(data); err == nil {
						field.ReflectValueOf(ctx, value).Set(reflect.ValueOf(t))
					} else {
						return 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)
					}
				default:
					return fallbackSetter(ctx, value, v, field.Set)
				}
				return nil
			}
		case *time.Time:
			field.Set = func(ctx context.Context, value reflect.Value, v interface{}) error {
				switch data := v.(type) {
				case **time.Time:
					if data != nil && *data != nil {
						field.ReflectValueOf(ctx, value).Set(reflect.ValueOf(*data))
					}
				case time.Time:
					fieldValue := field.ReflectValueOf(ctx, value)
					if fieldValue.IsNil() {
						fieldValue.Set(reflect.New(field.FieldType.Elem()))
					}

View on GitHub (pinned to 1d6ce99528)

Solutions

  1. Format the time string in a layout GORM recognizes (e.g. RFC3339 or the configured time format).
  2. Parse the string into time.Time before assigning it to the field.
  3. Check NowFunc / serializer configuration for custom time handling.

Example fix

Set time fields with time.Time values or strings in a parseable layout, or configure NowFunc/parse format accordingly.

When it happens

Trigger: Thrown at schema/field.go:854 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of go-gorm/gorm@1d6ce99528 (2026-08-15). Data as JSON: /api/errors/bc0c1757e950f6f3. Report an issue: GitHub.