In the original post “How to use SQL functions in conditions” I showed you how to use SQL functions in conditions by means of the magic “-!” marker with the following example:

$this->User->findAll(array('DATE(User.modified)' => '-!CURDATE()'));

This snippet returns all user records modified at the current day. Now John-Henrique asked in a comment how to do the contrary, i.e. select those records not modified at the current day.

There exist at least two possible ways to accomplish this, the simplest one is to use “<>”:

$this->User->findAll(array('DATE(User.modified)' => '<> -!CURDATE()'));

It creates the following SQL code:

... WHERE DATE(`User`.`modified`) <> CURDATE()

Another approach is to use the “NOT” keyword of SQL:

$this->User->findAll(array('NOT' => array('DATE(User.modified)' => '-!CURDATE()')));

With this snippet we get the following SQL statement:

... WHERE NOT (DATE(`User`.`modified`) = CURDATE())