Golang : Error reading timestamp with GORM or SQL driver
Problem :
It is common for application to read from database these days and sometimes a missing parameter in the database connection configuration can cause chaos. For instance, while attempting to read time stamp data from database, you get these funky errors :
(sql: Scan error on column index 2: unsupported driver -> Scan pair: []uint8 -> *time.Time)
and when you try to read time stamp from your database(MySQL, SQLite, etc), it becomes :
0001-01-01 00:00:00 +0000 UTC
Solution :
Make sure that your database connection is initialized with parseTime=true
parameter.
For example :
dbConn, err := gorm.Open("mysql", "username:password@tcp(xx.xx0.x65.xx4:3306)/dbname?charset=utf8&parseTime=true")
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+5.6k Cash Flow : 50 days to pay your credit card debt
+19.9k Golang : How to get struct tag and use field name to retrieve data?
+10k Golang : Embed secret text string into binary(executable) file
+6.5k Golang : Output or print out JSON stream/encoded data
+10.8k Golang : Read until certain character to break for loop
+6.9k Golang : Array mapping with Interface
+8.1k Your page has meta tags in the body instead of the head
+4.9k Golang : Print instead of building pyramids
+4.9k Golang : Convert lines of string into list for delete and insert operation
+18.2k Golang : Example for RSA package functions
+6k Apt-get to install and uninstall Golang