Skip to content

Instantly share code, notes, and snippets.

@shenli
Last active March 22, 2016 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shenli/bebb21bd997284f4b874 to your computer and use it in GitHub Desktop.
Save shenli/bebb21bd997284f4b874 to your computer and use it in GitHub Desktop.
MySQL Time test
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"time"
)
func main() {
dsn := "root:@tcp(127.0.0.1:3306)/test?parseTime=True"
db, err := sql.Open("mysql", dsn)
_, err = db.Exec("drop table if exists t_time;")
if err != nil {
panic(err)
}
_, err = db.Exec("create table t_time (c Time);")
if err != nil {
panic(err)
}
_, err = db.Exec("insert into t_time values (?);", time.Now())
if err != nil {
panic(err)
}
row := db.QueryRow("select * from t_time;")
var c string
row.Scan(&c)
fmt.Println(c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment