gocraft/dbr

Time format into DB

Closed this issue · 3 comments

when I insert record with

type DBMetrics struct {
	Time      time.Time `db:"Time"`
}
location, _ = time.LoadLocation("Europe/Berlin")
cur := time.Now()
m := &DBMetrics{}
m.Time = time.Date(cur.Year(), cur.Month(), cur.Day(), cur.Hour(), 0, 0, 0, location)

I want to get - '2017-03-29 14:57:00 +0200 CEST'
but have - '2017-03-29 12:57:00.000000'
because UTC

What's your table schema or column definition? Which db are you using? Which dbr method are you calling to insert/update ?
Also, why do you think time.Now().UTC().Format(timeFormat) would cause this problem ?

builder := s.StatSession.
		InsertInto("metrics").
		Columns("Day", "Time"...).
		Record(item)
fmt.Println(
                dbr.InterpolateForDialect("?", []interface{}{builder}, builder.Dialect))

I want to get - '2017-03-29 14:57:00 +0200 CEST'
but have - '2017-03-29 12:57:00.000000'

I found time interpolate method in mysql dialect

ok, I will write time in UTC, and convert it when need.