How to compare just the date, not the timestamp using LINQ

我与影子孤独终老i 提交于 2019-12-20 06:32:12

问题


I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back.

How could I write this same LINQ query if I'm only interested in the actual date value matching?

The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00

from t in UnitsOfWork _
where t.ImportDate = "08/30/2009" _
select t

回答1:


You can compare it as a string or you can use just the Date property on ImportDate

where t.ImportDate.ToString("yyyyMMdd") == "20090830"

or

where t.ImportDate.Date == new DateTime(2009,8,30)


来源:https://stackoverflow.com/questions/1354881/how-to-compare-just-the-date-not-the-timestamp-using-linq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!