Sometimes it is handy to use a (database-specific) SQL function in your find/findAll statements, e.g. a function which returns the current date. But how can this be done?

The obvious approach doesn’t work:

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

The function “CURDATE()” is escaped and treated as a string as you can see in the generated SQL statement:

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

To avoid the escaping we have to add the magical “-!” marker in front of the function name:

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

This will generate the expected SQL:

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

Hooray!

Thanks to Kabturek who mentioned this little trick some time ago in his blog.