MySQL STR_TO_DATE Returns NULL with %p

Can anyone explain why the first two return NULL?

SELECT STR_TO_DATE('2022/12/11 08:10AM','%Y/%m/%d %H:%i%%p'); -- returns null
SELECT STR_TO_DATE('2022/12/11 08:10 AM','%Y/%m/%d %H:%i% %p'); -- returns null
SELECT STR_TO_DATE('2022/12/11 08:10','%Y/%m/%d %H:%i%'); -- returns "2022-12-11 08:10:00"

Solution 1:

You can use this two format as the manual said:

SELECT STR_TO_DATE('2022/12/11 08:10 AM','%Y/%m/%d %h:%i%p')
SELECT STR_TO_DATE('2022/12/11 08:10:00 AM','%Y/%m/%d %r')

Solution 2:

%H is for 24 hour times which is not compatible with am/pm. Try using %h