Comparing dates in linq
Posted on 2011-05-03
return context.ScheduledKeywordEntities.Where(s => ((s.every_day == true || s.day == day)
&& (s.start_time >= time && s.end_time.Value <= time))
&& ((Convert.ToDateTime(s.date_executed).Date != DateTime.Today.Date)
|| (Convert.ToDateTime(s.date_executed).Date == DateTime.Today.Date && (s.time_executed < s.start_time || s.time_executed > s.end_time))))
.Select(s => new ScheduledKeywords
TimeTableID = s.timetable_id,
KeywordID = s.keyword_id,
KeyWord = s.keyword,
AdDisplayURL = s.ad_display_url
I have the above LINQ to SQL query. I am trying to compare dates and times and am having problems. I keep in getting - LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.Object)' method, and this method cannot be translated into a store expression.
How do I compare dates so that they are both in the right format?