问题描述
有没有一种方法可以比较Linq2Sql
中的两个DateTime
变量,而忽略时间"部分.
Is there a way to compare two DateTime
variables in Linq2Sql
but to disregard the Time part.
该应用程序将项目存储在数据库中并添加发布日期.我想保留确切的时间,但仍然可以按时完成日期.
The app stores items in the DB and adds a published date. I want to keep the exact time but still be able to pull by the date itself.
我想比较12/3/89 12:43:34
和12/3/89 11:22:12
,并忽略实际时间,因此将两者视为相同.
I want to compare 12/3/89 12:43:34
and 12/3/89 11:22:12
and have it disregard the actual time of day so both of these are considered the same.
我想我可以在比较之前将一天中的所有时间都设置为00:00:00
,但实际上我确实想知道一天中的时间,我也只希望能够按日期进行比较.
I guess I can set all the times of day to 00:00:00
before I compare but I actually do want to know the time of day I just also want to be able to compare by date only.
我发现一些具有相同问题的代码,它们分别比较年,月和日.有更好的方法吗?
I found some code that has the same issue and they compare the year, month and day separately. Is there a better way to do this?
推荐答案
尝试使用DateTime
对象上的Date
属性...
try using the Date
property on the DateTime
Object...
if(dtOne.Date == dtTwo.Date)
....
这篇关于如何仅将Linq中DateTime类型中的没有日期的Date与带有实体框架的SQL进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!