You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') < fechaInicio)' at line 1 Sql:SELECT targetId FROM crm_op_tareas WHERE crm_op_tareas.targetId = 5785 AND tipoTargetId=2 AND (DATE_SUB(CURDATE(),INTERVAL DAY) < fechaInicio)