Mysql – Warning: #1292 Incorrect datetime error when using DATE_ADD()

datemariadbMySQL

Doing this works fine:

SELECT * FROM table WHERE foo < '2021-01-09 00:00:00'

But this one:

SELECT * FROM table WHERE DATE_ADD('foo', INTERVAL 5 DAY) < '2021-01-09 00:00:00'

results in

Warning: #1292 Incorrect datetime value: 'foo'

What could possibly be causing this?

(MariaDB 10.4.17)

Best Answer

You try to add to the string 'foo' 5 days.

Use backticks for column names

SELECT * FROM table WHERE DATE_ADD(`foo`, INTERVAL 5 DAY) < '2021-01-09 00:00:00'