diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index d877c32e9e843..66188212bba33 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1418,6 +1418,7 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) { {"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 59, 58, 000000000, time.Local)}, {"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)}, {"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)}, + {"2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2003, 1, 2, 10, 11, 12, 1200000, time.Local)}, {"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, types.KindMysqlTime, time.Time{}}, {"10:20:10AM", "%H:%i:%S%p", false, types.KindMysqlTime, time.Time{}}, // test %@(skip alpha), %#(skip number), %.(skip punct) diff --git a/types/time.go b/types/time.go index 1cf8783fe354a..a2a03ec076180 100644 --- a/types/time.go +++ b/types/time.go @@ -3225,7 +3225,7 @@ func microSeconds(t *CoreTime, input string, ctx map[string]int) (string, bool) if !ok { return input, false } - for v > 0 && v*10 < 1000000 { + for i := length; i < 6; i++ { v *= 10 } t.setMicrosecond(uint32(v))