Search code examples
c#sql-serversimple.data

Simple.Data subtract days from date time in where clause


I am using Simple.Data (version 0.19.0.0) against a SQL Server back end database and would like a query such as the one below to take 25 days from a date to compare against the date now;

DateTime dtNow = DateTime.Now.Date;        

var pool = db.Pools.FindAll(db.Pools.Status == 1
              && db.Pools.EndDate - 25 > dtNow)
           .Select(db.Pools.AllColumns());

I have tried using DATEADD but get an error that the function is not recognised, I guess because the column name is not the first parameter of the method.

Is this kind of thing possible in Simple.Data, or should I ignore the date in the query and perform the check in a foreach loop following?

Thanks in advance.


Solution

  • I overcame the problem by using a where clause on my query with a >= and < date range as suggested in how to search by date question.