1

I am using simple.data for my project. I have a column createdDate. this is a datetime column. if i passed in a date string "05/06/2006". I need to get all records created in that day. how can i do that using simple.data?

following code is not working. i only need to compare the date, not the time. hwo can i modify it to get it work.

        var list = _db.DocumentLog.All();

        if (!string.IsNullOrWhiteSpace(searchDate))
        {
            var dt = DateTime.ParseExact(searchDate, "MM/dd/yyyy", null);

            list = list.Where(_db.DocumentLog.CreatedDate == dt);
        }
qinking126
  • 11,385
  • 25
  • 74
  • 124

1 Answers1

3

Replace your search with:

list.Where(_db.DocumentLog.CreatedDate >= dt 
        && _db.DocumentLog.CreatedDate < dt.AddDays(1));

That will give you everything created on or after midnight of the given date, but before the next day - i.e. one full day.

Bobson
  • 13,498
  • 5
  • 55
  • 80