LINQ to Entities for subtracting 2 dates

Posted by Michael I on Stack Overflow See other posts from Stack Overflow or by Michael I
Published on 2009-02-20T19:13:16Z Indexed on 2010/04/04 4:53 UTC
Read the original article Hit count: 1665

I am trying to determine the number of days between 2 dates using LINQ with Entity Framework. It is telling me that it does not recognize Subtract on the System.TimeSpan class

Here is my where portion of the LINQ query.

where ((DateTime.Now.Subtract(vid.CreatedDate).TotalDays < maxAgeInDays))

Here is the error I receive in the VS.NET debugger

{"LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method, and this method cannot be translated into a store expression."}

Am I doing something wrong or is there a better way to get the number of days between 2 DateTimes in the entity framework?

thanks Michael

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about linq-to-entities