go-mssqldb
go-mssqldb copied to clipboard
proposal: allow config setting to return date/time types in local time
This driver return all times in UTC. I propose add an option to the connection string that would return times in local time instead of UTC.
server=X;user id=X;password;X;local_time=1
Is there a similar option in ADODB driver?
@denisenkom I'm not sure what driver you're referring to, but this seems inconsistent among Go drivers. PostgreSQL uses time.Local (SQLite I think, too), MySQL has it configurable, etc.
@kardianos: Pull request https://github.com/denisenkom/go-mssqldb/pull/284 from @andreynering fixed most of the problem, but you suggested defining the location on the driver, not package. Do you mean just adding uselocalTime bool to type Driver, or did you have something more sophisticated in mind?
Hi,
What's the status of this enhancement? Would really help on a job I've got where all data on a legacy system is in local time.
I currently use something like this to read the values as "local time", instead of UTC. Would like to hear if others do something similar...
type lTime struct{ time.Time }
func (l *lTime) Scan(value interface{}) error {
switch v := value.(type) {
case time.Time:
l.Time = time.Date(v.Year(), v.Month(), v.Day(), v.Hour(), v.Minute(), v.Second(), v.Nanosecond(), time.Local)
}
return nil
}
Did anything change? Is there an option by now? The workaround works, but it is not very handy...
I currently use something like this to read the values as "local time", instead of UTC. Would like to hear if others do something similar...
type lTime struct{ time.Time } func (l *lTime) Scan(value interface{}) error { switch v := value.(type) { case time.Time: l.Time = time.Date(v.Year(), v.Month(), v.Day(), v.Hour(), v.Minute(), v.Second(), v.Nanosecond(), time.Local) } return nil }