Standard library / database/sql
sql.NullTime
Represents a potentially NULL database value; Valid distinguishes SQL NULL from a Go zero value. Expected stdout: 'true\nfalse\n'.
Formal Syntax & Structure
go syntaxgo
type NullTime struct { Time time.Time Valid bool}Working Example
Example Snippetgo
package main
import ( "database/sql" "fmt" "time")
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}func main() { var n sql.NullTime check(n.Scan(time.Unix(0, 0).UTC())) fmt.Println(n.Valid) check(n.Scan(nil)) fmt.Println(n.Valid)}