方法一:使用DateTime.Compare 方法
public static int Compare( DateTime t1, DateTime t2 )
t1 早于 t2:小于零
t1 与 t2 相同:零
t1 晚于 t2:大于零
示例:
DateTime ctime = Convert.ToDateTime("2013-07-14 04:00:00.000"); DateTime today = DateTime.Now; DateTime.Compare(today,ctime)>0
DateTime now = DateTime.Now; var policypro = _db.PolicyProducts.SingleOrDefault(p => p.Status == true && DateTime.Compare(now,p.StartDate)>=0&&DateTime.Compare(now,p.EndDate)<=0);
方法二:直接用:!=,>,<,>=,<=进行对比
var item = _db.Pol.SingleOrDefault(createdate >= p.StartDate && createdate <= p.EndDate);
学习交流群:364976091