title: Date Difference Logic in LINQ
body: <p>I'm attempting to access data from two different database tables and then join them together on two fields using LINQ in C#.  I believe that I have a logically sound overall working approach.  Part of the problem I'm running into is that I'm filtering the data from both tables prior to joining them, because the tables have far too much data and it would cause a crash.</p>
  
  <p>The main problem is that for one of the tables I need to pull only data that has a timestamp (column) value of today.  The timestamp value is of type System.DateTime?.</p>
  
  <p>I've tried a few different ways:</p>
  
  <pre><code>        DateTime? currentDate = System.DateTime.Now;
  
          var second_data = (from b in this.database.table
              where EntityFunctions.DiffDays(b.timeStamp.Value, currentDate) == 0
              select b);
  </code></pre>
  
  <p>I'm under the impression this doesn't work because there's no function in the database to handle it.  Inner Exception: '{"FUNCTION database.DiffDays does not exist"}'</p>
  
  <pre><code>        var second_data = (from b in this.database.table
              where b =&gt; b.timeStamp.Value.Date == DateTime.Now.Date
              select b);
  </code></pre>
  
  <p>This doesn't work because 'The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.'</p>
  
  <pre><code>        var second_data =
              this.database.table.Where(sd =&gt; sd.timeStamp.Value.Date == DateTime.Now.Date);
  </code></pre>
  
  <p>But this again fails because of the use of .Date.</p>
  
  <p>Unfortunately, because I don't have the memory to hold all that data, the possibility of of pulling all the data first and then running date logic on it is out of the question.  If anyone could give any insight on how I might be able to solve this problem it would be greatly appreciated, thank you.</p>