I am pretty new to golang and gorm so, probably, this is an old question: I have a table in postgresql named datetime with type timestamp
I am trying to retrieve it using gorm in a golang project with this mapping
DateTime time.Time `gorm:"datetime:timestamp"`
But when i run the code i see that it retrieves this value:
0001-01-01 00:00:00 0000
How can i solve this ?
CodePudding user response:
DateTime time.Time gorm:"datetime:timestamp;default:CURRENT_TIMESTAMP"
or
DateTime time.Time gorm:"datetime:timestamp;default:DEFAULT"
try this. This will store current time. In your case you are not storing any data that's why it retrieves 0001-01-01 00:00:00 0000
CodePudding user response:
I found the solution and it was pretty simple to be honest. The field was mapped as
DateTime
which i guess is translated as "date_time" when performing the query to extract the data; so, i changed the mapping to
Datetime
which is translated to "datetime", and it worked