I'm trying to compare two time.Time
dates in Go using the Before
function.
The issue is that one of these dates comes from a MySQL datetime
field.
When I Scan the result, it is saved as a UTC timezone, but I wrote in database in my local time (UTC +1). This is a problem when I compare the database date with a time.Now()
that is in my local time.
I extracted the date with a scan into a time.Time
variable with ?parseTime=true
on the connection string.
Do you have any suggestion? I don't want to add 1 hour after reading the date from the DB because it can cause me problems with summer time (UTC +2).
I tried to extract the date from DB and convert with UTC function:
data, _ = time.Parse("2006-01-02 15:04:05", data.UTC().Format("2006-01-02 15:04:05"))
but without any success.