Standard library / database/sql

sql.NullTime.Value()

Implements driver.Valuer, returning nil for an invalid wrapper and a converted driver value for a valid wrapper. Expected stdout: 'true\ntrue\nfalse\n'.

Formal Syntax & Structure

go syntaxgo
func (n NullTime) Value() (driver.Value, error)

Return Value

(driver.Value, error)

Implements driver. Check returned errors where applicable.

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)  v := must(n.Value())  fmt.Println(v != nil)  check(n.Scan(nil))  fmt.Println(n.Valid)}
Go Reference