title: MongoDB Linq date difference in WHERE statement
body: <p>I have a class, that contains two DateTime variables, "From" and "To":</p>
  
  <pre><code>public class A
  {
      public DateTime From;
      public DateTime To;
  }
  </code></pre>
  
  <p>If I'd want to get all objects, where From and Two are only 2 hours apart, I'd write something like this:</p>
  
  <pre><code>_db.GetCollection&lt;A&gt;("A").Find( (x.To-x.From).TotalMinutes &lt;= 120).ToList();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var Minutes120 = new TimeSpan(2, 0, 0);
  _db.GetCollection&lt;A&gt;("A").Find( (x.To-x.From) &lt;= Minutes120).ToList();
  </code></pre>
  
  <p>or even</p>
  
  <pre><code>var Minutes120 = new TimeSpan(0, 120, 0).Ticks;
  _db.GetCollection&lt;A&gt;("A").Find( (x.To.Ticks-x.From.Ticks) &lt;= Minutes120).ToList();
  </code></pre>
  
  <p>However, none of the above work. I always get <strong>"...is not supported."</strong> error.</p>
  
  <p>Is there any way of doing a search like above without having to save the time difference together with the dates in a separate property? It seems a little overkill to save the time difference although I need it only in one query.</p>