Warning: #1292 Incorrect datetime value

Muiter :

Any ideas why the error Warning: #1292 Incorrect datetime value: '1' occurs in this MySQL query?

UPDATE dossiers SET
attest_status = 'verstuurd'
WHERE `datum_dossier` = (NOW() - INTERVAL 30 DAY > datum_dossier) AND attest != 'geen'

Field datum_dossier is set as date and has no values of 0000-00-00.

I have another query that is working fine though:

UPDATE dossiers SET
reden_vervallen = 'Automatisch na 30 dagen',
datum_vervallen = NOW(),
status = 'vervallen'
WHERE soort = 'offerte' AND status = 'geoffereerd' AND (NOW() - INTERVAL 30 DAY > datum_dossier)
Bill Karwin :

Let's break this down:

WHERE `datum_dossier` = (NOW() - INTERVAL 30 DAY > datum_dossier)

This is a boolean comparison between datum_dossier (I assume this is a date) and the right-hand-side, which is itself a boolean expression:

(NOW() - INTERVAL 30 DAY > datum_dossier)

This is a greater-than expression. It will not return a date, it will return a 1 (true) or 0 (false).

So you're trying to compare a date datum_dossier to a boolean value 1 or 0, which isn't a valid comparison:

WHERE `datum_dossier` = (1)

Whereas in your second query, it's just a series of boolean terms between AND operations:

WHERE soort = 'offerte' 
 AND status = 'geoffereerd' 
 AND (NOW() - INTERVAL 30 DAY > datum_dossier)

You are not comparing any boolean to a date, so it's just fine.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=9534&siteId=1