Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq | Date | Subtraction with matching issue
    text
    copied!<p>I want to check 1 day old created record(s), and below is my code. my problem is, it does returning any record even if I do have a match.</p> <p>And even I run it on LinqPad, It just outputing blank result.</p> <pre><code>from x in Users where (DateTime.Today - x.CreatedDate).ToString().Equals("1.00:00:00") select x </code></pre> <p>but when i try to remove the "where"</p> <pre><code>from x in Users select x </code></pre> <p>here are may result below, as you can see, there is 1 matches:</p> <pre><code>ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/6/2009 12:00:00 AM | Result : 1.00:00:00 | Condition : True ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False ToDay : 8/7/2009 12:00:00 AM | CreatedDate : 8/7/2009 12:00:00 AM | Result : 00:00:00 | Condition : False NUnit.Framework.AssertionException: Expected: greater than 0 But was: 0 </code></pre> <p>I am running this under IQueryable, AddDays and alike are not supported, even though some post below will run on LinqPad, but still not supported by IQueryable on c#.</p> <p>So may solution is:</p> <pre><code>IList&lt;Users&gt; users = new List&lt;Users&gt;(); var qry = from x in Users select x; foreach(user in qry) { if(!DateTime.Today - x.CreatedDate).ToString().Equals("1.00:00:00")) continue; users.Add(user); } .. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload