Skip to content

datetime timezone bug #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
slene opened this issue Jan 3, 2014 · 5 comments
Closed

datetime timezone bug #203

slene opened this issue Jan 3, 2014 · 5 comments

Comments

@slene
Copy link

slene commented Jan 3, 2014

Go-MySQL-Driver version 1.0.3
go version go1.2 linux/amd64

Before version 1.0.3 (included) everything is ok. But after this version. Has a timezone bug.

example:

In linux:

# date
Fri Jan  3 14:49:44 CST 2014

In Mysql 5.5

mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | SYSTEM |
+------------------+--------+
mysql> SELECT @@session.time_zone;
+---------------------+
| @@session.time_zone |
+---------------------+
| SYSTEM              |
+---------------------+
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2014-01-03 14:50:10 |
+---------------------+

In go

db, _ := sql.Open("mysql", "root:root@/orm_test?charset=utf8")
fmt.Println(time.Now())
res, _ := db.Exec("INSERT INTO doc (`time`)VALUES(?)", time.Now())
id, _ := res.LastInsertId()
fmt.Println(id)
var t string
db.QueryRow("SELECT `time` FROM doc WHERE id = ?", id).Scan(&t)
fmt.Println(t)

Before version 1.0.3 (included) output is

2014-01-03 14:55:50.430158786 +0800 CST
1
2014-01-03 14:55:50

Latest version output is. The timezone always is UTC. Can not detect the current timezone.

2014-01-03 14:59:31.729418163 +0800 CST
2
2014-01-03 06:59:31

What's wrong with this. May I miss something?

slene added a commit to slene/mysql that referenced this issue Jan 3, 2014
@arnehormann
Copy link
Member

We changed that because we don't have a reliable way to convert between timezones when server and client are on different machines and - worst case - their clocks are off. See the discussion in #9.
It's also referenced in the readme, just use the loc parameter in the dsn: https://github.com/go-sql-driver/mysql#timetime-support, end of second paragraph.

@slene slene closed this as completed Jan 9, 2014
@akamensky
Copy link

@arnehormann How do I fix this behavior?

I am storing data sampling taken on client, which by-desgin may have a different timezone than any another client.

This is a huge problem when frameworks start assuming something for developer... I need to preserve TZ information. If I did not need to, I would be dealing with this in my code.

@methane
Copy link
Member

methane commented Jul 18, 2016

This is a general MySQL question. It isn't specific to this driver.
So there should be better place to talk about this, other than here.

My recommendation is store time in UTC always.
Or you can add another column to store TZ.

@arnehormann
Copy link
Member

As @methane says. I'll just defer to @xaprb here, follow his advice if at all possible: http://www.xaprb.com/blog/2014/01/30/timestamps-in-mysql/

@saurabh-gupta7869
Copy link

@slene, What was the value stored in mysql table in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants