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
+10.1k Golang : Characters limiter example
+7k Golang : Load DSA public key from file example
+7.1k Golang : Get final or effective URL with Request.URL example
+16.2k Golang : Parse date string and convert to dd-mm-yyyy format
+14k Golang : Find location by IP address and display with Google Map
+16.8k Golang : Get command line arguments
+6.5k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+7.8k Golang : Accept any number of function arguments with three dots(...)
+4.9k Golang : Launching your executable inside a console under Linux
+12.6k Golang : Tutorial on loading GOB and PEM files
+4.9k PHP : Get client IP address
+5.9k How to let Facebook Login button redirect to a particular URL ?