Use datadd or datediff on literal values only

Avoid using the dateadd and datediff statements when the result cannot be transformed to a literal value in the where clause

Failing to return a literal value causes the driver to query all records from the table before filtering them, which may affect query performance.

Use the following example to determine when to use dateadd or datediff. In the efficient query, the statement is transformed to select number from incident where closed_at= ‘2015-05-05’;, allowing the driver to query fewer records from the instance.
Table 1. Example queries
Inefficient query Efficient query
select number from incident where datediff(day, curdate(), closed_at)=-1; select number from incident where closed_at=dateadd(day, -1, curdate());