Skip to content

Instantly share code, notes, and snippets.

@shenli shenli/time.go
Last active Mar 22, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.