Hi Ingmar, this is what you should do:
// define the funcion and apply to an entity field (important: use a field that have a type
// of the DBFunction's result, in this case INT).
EntityField fieldDateDiff = OrderFields.OrderId.SetExpression(
new DbFunctionCall("DATEDIFF(day, {0}, {1})", new object[] { OrderFields.OrderDate, OrderFields.ShippedDate }) );
// use above field to filter the data, in this case we use a between predicate
IPredicateExpression filter = new PredicateExpression( new FieldBetweenPredicate(fieldDateDiff, 4, 5) );
// fetch orders
orders.GetMulti(filter);
In above example I WANT ALL ORDERS THAT DELAY BETWEEN 4 AND 5 DAYS TO BE SHIPPED.
So apply to your scenario and let us know if it work as expected to you