Yesterday in MySQL

Sometimes the simplest things just won’t stay in your head. Personally I can never remember code for date based calculations, and it easier to find what I want here than look it up on http://dev.mysql.com/doc/.

Here is a very simple way of comparing (or getting) dates:

Example delete all records older than 1 day from the notes.

1
2
 
DELETE FROM notes WHERE created <= DATE_ADD(CURDATE(), INTERVAL -1 DAY);

Read the manual entry for the MySQL DATE_ADD function.