{"record":{"id":"966cc21fab4a54e9","repo":"go-sql-driver/mysql","slug":"can-t-convert-t-to-time-time","errorCode":null,"errorMessage":"can't convert %T to time.Time","messagePattern":"can't convert %T to time\\.Time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nulltime.go","lineNumber":62,"sourceCode":"\t\treturn\n\t}\n\n\tswitch v := value.(type) {\n\tcase time.Time:\n\t\tnt.Time, nt.Valid = v, true\n\t\treturn\n\tcase []byte:\n\t\tnt.Time, err = parseDateTime(v, time.UTC)\n\t\tnt.Valid = (err == nil)\n\t\treturn\n\tcase string:\n\t\tnt.Time, err = parseDateTime([]byte(v), time.UTC)\n\t\tnt.Valid = (err == nil)\n\t\treturn\n\t}\n\n\tnt.Valid = false\n\treturn fmt.Errorf(\"can't convert %T to time.Time\", value)\n}\n\n// Value implements the driver Valuer interface.\nfunc (nt NullTime) Value() (driver.Value, error) {\n\tif !nt.Valid {\n\t\treturn nil, nil\n\t}\n\treturn nt.Time, nil\n}\n","sourceCodeStart":44,"sourceCodeEnd":72,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/03d76c7e07908e255ce62d126d07ede3f2365d86/nulltime.go#L44-L72","documentation":"NullTime.Scan accepts only nil, time.Time, []byte (a date/time string), or string. Any other concrete type reaches the fallback and yields this error naming the offending type. It means the value being scanned into a NullTime is incompatible.","triggerScenarios":"Scanning a numeric/decimal/integer column into a *mysql.NullTime, or calling nt.Scan with an int64/float64/struct value. E.g. a column stored as a unix epoch integer scanned directly into NullTime.","commonSituations":"Column-type mismatch (times stored as BIGINT epoch or DECIMAL); feeding a driver.Value of the wrong shape into Scan; schema drift.","solutions":["Scan into the column's actual type (e.g. int64) and convert to time.Time yourself.","Write a custom sql.Scanner that converts the source type before assigning.","Ensure the source column is a MySQL DATE/TIME/DATETIME/TIMESTAMP so the driver yields a time.Time (with parseTime=true) or a scannable string."],"exampleFix":"// before\nvar nt mysql.NullTime\nrows.Scan(&nt) // column is BIGINT epoch -> error\n// after (scan int, convert manually)\nvar epoch int64\nrows.Scan(&epoch)\nnt := mysql.NullTime{Valid: epoch != 0}\nif nt.Valid {\n    nt.Time = time.Unix(epoch, 0)\n}","handlingStrategy":"validation","validationCode":"// Check the concrete type before scanning when the source is uncertain.\nswitch v := src.(type) {\ncase nil, time.Time, []byte, string:\n    nt.Scan(v)\ndefault:\n    return fmt.Errorf(\"unsupported NullTime source: %T\", v)\n}","typeGuard":"func isNullTimeScannable(v any) bool {\n    switch v.(type) {\n    case nil, time.Time, []byte, string:\n        return true\n    }\n    return false\n}","tryCatchPattern":"// NullTime.Scan returns this error; check it.\nif err := nt.Scan(val); err != nil {\n    // convert val to a supported type and retry\n}","preventionTips":["Confirm the source column type matches a temporal MySQL type.","Use parseTime=true so temporal columns yield time.Time directly.","Wrap non-standard sources in a custom Scanner."],"tags":["go","mysql","types","scan","time"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}