When attempting to retrieve a time value from a MySQL database using Go, you may encounter an "unsupported driver -> Scan pair" error. This issue stems from the default behavior of Go's MySQL driver not automatically converting DATE and DATETIME values to time.Time objects.
To resolve this issue, add parseTime=true to your MySQL connection string. This parameter instructs the driver to perform the necessary parsing for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
If you cannot use current_timestamp and must use current_time, you'll need to perform the parsing yourself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
This custom parsing type converts the retrieved byte slice into a time.Time object using a specific time format ("15:04:05" in this case).
The above is the detailed content of How to Parse Time from a MySQL Database in Go?. For more information, please follow other related articles on the PHP Chinese website!