Search code examples
gogo-pg

why insert time in go-pg is changed


I want to insert time to database using go-pg, but value is change after inserted.

toRound := time.Now()
date := time.Date(toRound.Year(), toRound.Month(), toRound.Day(), 0, 0, 0, 0, toRound.Location())

value of date is 2020-03-18 00:00:00 +0700 WIB

and to insert using go-pg

reportMessage := &ReportMessage{
                    Total:      ii,
                    Date:            date
                }

_, err = p.ormer.Model(reportMessage).Returning("id").Insert()

value of date after inserted is 2020-03-17 17:00:00+00:00:00

it's looks like because of timezone

how to insert time exactly as raw value without affected by timezone or anything?


Solution

  • try use an UTC date in model:

    reportMessage.Date := date.UTC()