go-mssqldb icon indicating copy to clipboard operation
go-mssqldb copied to clipboard

proposal: allow config setting to return date/time types in local time

Open andreynering opened this issue 7 years ago • 6 comments

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

andreynering avatar Mar 01 '17 16:03 andreynering

Is there a similar option in ADODB driver?

denisenkom avatar Aug 08 '17 17:08 denisenkom

@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.

andreynering avatar Aug 08 '17 17:08 andreynering

@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?

paulcager avatar Mar 29 '18 12:03 paulcager

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.

mixmastamyk avatar May 18 '18 19:05 mixmastamyk

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
}

johanfo avatar Sep 22 '18 15:09 johanfo

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
}

SchulteMK avatar Sep 17 '21 10:09 SchulteMK