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.
And even I run it on LinqPad, It just outputing blank result.
from x in Users
where (DateTime.Today - x.CreatedDate).ToString().Equals("1.00:00:00")
select x
but when i try to remove the "where"
from x in Users
select x
here are may result below, as you can see, there is 1 matches:
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
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#.
So may solution is:
IList<Users> users = new List<Users>();
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);
}
..