Catalogue
created_at (datetime) gets stored in UTC with go-sql-driver/mysql

created_at (datetime) gets stored in UTC with go-sql-driver/mysql

🌐 日本語で読む

Environment

  • go-sql-driver/mysql version 1.2

Conclusion

Set parseTime=true and loc=Asia%2FTokyo as shown below.

1
db, err := sql.Open("mysql", "user:passward@/dbname?parseTime=true&loc=Asia%2FTokyo")

When loc=xxxx is not specified, local is used, and even if you pass time.Now() to a datetime column on INSERT, it gets rewritten to UTC time.

This one tripped me up for a bit.

created_at (datetime) gets stored in UTC with go-sql-driver/mysql

https://kenzo0107.github.io/en/2015/08/19/gosql-driver-mysql-created_at-utc/

Author

Kenzo Tanaka

Posted on

2015-08-19

Licensed under