diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index dd8177d4bd..3e4922731e 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -3732,7 +3732,7 @@ CREATE TABLE tab3 ( }, { // When the session's time zone is set to UTC, NOW() and UTC_TIMESTAMP() should return the same value - Query: `select @@time_zone, NOW() = UTC_TIMESTAMP();`, + Query: `select @@time_zone, NOW(6) = UTC_TIMESTAMP();`, Expected: []sql.Row{{"+00:00", true}}, }, { @@ -3746,7 +3746,7 @@ CREATE TABLE tab3 ( }, { // When the session's time zone is set to +2:00, NOW() should report two hours ahead of UTC_TIMESTAMP() - Query: `select @@time_zone, TIMESTAMPDIFF(MINUTE, NOW(), UTC_TIMESTAMP());`, + Query: `select @@time_zone, TIMESTAMPDIFF(MINUTE, NOW(6), UTC_TIMESTAMP());`, Expected: []sql.Row{{"+02:00", -120}}, }, { diff --git a/sql/expression/function/time.go b/sql/expression/function/time.go index 5a03c8db08..405e1265ff 100644 --- a/sql/expression/function/time.go +++ b/sql/expression/function/time.go @@ -990,7 +990,7 @@ func (n *Now) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { nano := precision * (t.Nanosecond() / precision) // Generate a new timestamp - tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, t.Location()) + tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, time.UTC) return tt, nil } @@ -1099,7 +1099,8 @@ func (ut *UTCTimestamp) Children() []sql.Expression { return nil } func (ut *UTCTimestamp) Eval(ctx *sql.Context, _ sql.Row) (interface{}, error) { t := ctx.QueryTime() // TODO: UTC Timestamp needs to also handle precision arguments - tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location()) + nano := 1000 * (t.Nanosecond() / 1000) + tt := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), nano, t.Location()) return tt.UTC(), nil }