如何在不使用时间的DateTime类型在C#中只比较日期? [英] How to compare only Date without Time in DateTime types in C#?

查看:1196
本文介绍了如何在不使用时间的DateTime类型在C#中只比较日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在LINQ2SQL比较2日期时间变量,但忽略了时间的部分。

Is there a way to compare 2 DateTime variables in Linq2Sql but to disregard the Time part.

在应用程序商店在DB项目,并增加了出版日期。我想保留的确切时间,但是仍然可以通过日期本身去拉。

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.

我想比较89年12月3日12点43分34秒和89年12月3日十一时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.

我发现了一些code,具有相同的问题,他们比较了年,月,日分开。有没有更好的方式来做到这一点?

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 对象...

try using the Date property on the DateTime Object...

if(dtOne.Date == dtTwo.Date)
    ....

这篇关于如何在不使用时间的DateTime类型在C#中只比较日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆