Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value

Tags:

mysql

pdo

mariadb

This is the error I am getting.

PDOException: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\x9F\x98\xB3' for column 'string' at row 1'

I know the problem here. The column table is using utf8. The utf8 encoding cannot store 4 byte characters so it errors. A way to get around this could be to use utf8mb4 instead.

My question instead is about the error message. We are using MariaDB. Why does it say "Invalid datetime format" in the error message? This is a text field. There is nothing to do with datetime in the query being run.

This "Invalid datetime format" comes up often for a variety of errors but seems unrelated to the actual source of the error.

like image 807
Computer User Avatar asked Feb 21 '26 13:02

Computer User


1 Answers

Yes, I've seen this before.

I suppose it's a bug on the mariadb side, where all errors on the incorrect values are dubbed as "incorrect datetime value".

I see no harm here though beside a little confusion. Just keep in mind the issue and treat it as "incorrect text value"

like image 107
Your Common Sense Avatar answered Feb 23 '26 01:02

Your Common Sense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!