Search code examples
postgresqlgogo-gorm

retrieve timestamp from postgresql with GORM in GOLANG


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 ?


Solution

  • 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