看到标题,我想很多人都会马上想到用DateTime.Now.Date来进行对比,刚开始做的时候我也是这个样子的,但是去数据源的时候,系统报错,提示不支持Date属性,在网上看了很多解决办法,有一个可行的是:System.Data.Objects.EntityFunctions.DiffDays(a.FillTime , DateTime.Now) < -1
通过这个语句获取时间差,但是这个样子只能获取与当前时间相差一天的数据,并不能达到我想要的效果,后来想想,用下面办法解决了,。
string str = DateTime.Now.ToShortDateString();
DateTime time1 = Convert.ToDateTime(str + " 0:00:00");
DateTime time2 = Convert.ToDateTime(str + " 23:59:59");
var number = from a in context.Documents
where a.FillTime >= time1 & a.FillTime <= time2
select a;
记下来以防以后还会用!!