0

In the db table the dates are stored in a char(8) field in this format yyyyMMdd. How do I query for a date range?

I tried the following and it does not work:

context.Where(p=> Convert.ToDateTime(p.Date) >= Convert.ToDateTime('20120411');
context.Where(p=> Convert.ToInt32(p.Date) >= Convert.ToInt32('20120411');
context.Where(p=> int.Parse(p.Date) >= int.Parse('20120411');

From what I've read a possible way is to use EntityFunctions class but I'm not sure how to construct the query. Any ideas on how to do this?

dm80
  • 1,228
  • 5
  • 20
  • 38

2 Answers2

0

Convert the test string to a date:

context.Where(p=> Convert.ToDateTime(p.Date) >= DateTime.Parse("2012/04/11 00:00:00");
Brian Leeming
  • 11,540
  • 8
  • 32
  • 52
  • LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression. – dm80 Apr 11 '12 at 21:03
0
context.Where(p=> p.Date.CompareTo("20120411") >= 0);
Steve Mallory
  • 4,245
  • 1
  • 28
  • 31