diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 2c5d409b5a20c..436d0a87289b2 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1256,6 +1256,8 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) { {"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, 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, 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, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)}, + {"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, time.Time{}}, + {"10:20:10AM", "%H:%i:%S%p", false, time.Time{}}, } fc := funcs[ast.StrToDate] diff --git a/types/time.go b/types/time.go index 8b1efd4231cd3..f9e49a238d929 100644 --- a/types/time.go +++ b/types/time.go @@ -1920,6 +1920,9 @@ func mysqlTimeFix(t *MysqlTime, ctx map[string]int) error { _ = yearOfDay } if valueAMorPm, ok := ctx["%p"]; ok { + if _, ok := ctx["%H"]; ok { + return ErrInvalidTimeFormat.GenWithStackByArgs(t) + } if t.hour == 0 { return ErrInvalidTimeFormat.GenWithStackByArgs(t) } @@ -2300,6 +2303,7 @@ func hour24Numeric(t *MysqlTime, input string, ctx map[string]int) (string, bool return input, false } t.hour = v + ctx["%H"] = v return input[length:], true }