D
D
DrunkMaster2016-09-02 21:57:00
MySQL
DrunkMaster, 2016-09-02 21:57:00

Why such SQL condition deletes data?

DELETE FROM `table` WHERE `label` < (CURDATE()-15)
I was hoping that it would delete records older than 15 days, but in fact, on the 1st, it deletes all data for the previous month, i.e. even for yesterday.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2016-09-02
@DrunkMaster

Such a condition is incorrect.
For time range manipulation use DATE_SUB/DATE_ADD

DELETE FROM `table` WHERE `label` < DATE_SUB(CURDATE(), INTERVAL 15 DAY)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question