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
+6k Java : Human readable password generator
+10.5k Golang : Select region of interest with mouse click and crop from image
+7k Golang : Array mapping with Interface
+23.4k Golang : Read a file into an array or slice example
+12.8k Golang : Convert IPv4 address to packed 32-bit binary format
+8.1k Golang : Get final or effective URL with Request.URL example
+16.9k Golang : Capture stdout of a child process and act according to the result
+8.6k Golang : Combine slices but preserve order example
+5.1k Python : Create Whois client or function example
+9.3k Golang : Find the length of big.Int variable example
+13k Golang : Calculate elapsed years or months since a date
+5.1k Golang : Experimental Jawi programming language