比较两种不同格式的DateTime [英] Compare Two different formats of the DateTime
问题描述
我的表格中有 EndDate
列,接受这样的记录
I have EndDate
column in my table which accepts records like this
2014-10- 29 00:00:00.000
现在我想将这个 DateTime
与日期。为此,我这样做了: -
Now I want to compare this DateTime
with present date . For that , I did like this :-
var today=DateTime.Now;
var LstEvents = (from t in _context.Tournaments
where t.SiteId == siteId && t.EndDate != null
&& t.EndDate < today
select t).ToList();
但是 t.EndDate<今天
不按我的要求返回结果。我今天做了添加手表,并检查了价值,它的格式就像
But t.EndDate < today
is not returning results as I wanted . I did Add Watch for today and checked the value and it's format was like
今天{11/3/2014 8:12 :00 PM} System.DateTime
所以我的日期无法比较。
任何帮助将不胜感激
Therefore my dates are unable to be compared . Any help would be much appreciated
谢谢!!
推荐答案
我已经粘贴的代码是绝对正确的。我知道 DateTime
格式是无关紧要的。无论是来自数据库还是我在 C#
代码中使用它。我有点困惑,因为我认为如果数据库中的 DateTime
记录设置为某种格式,那么它不能与 DateTime
C#中的值。要么我们要改变格式或做点什么。无论如何,谢谢guyzz的帮助。
The code I have pasted was absolutely correct . I got to know that DateTime
format is irrelevant . Whether it is coming from database or I have used it in C#
code . I was bit confused as I thought that if the DateTime
record in database is set in some format then it cannot be compared with the DateTime
value in C# . Either we have to change the format or do something . Anyway , Thanks guyzz for your help.
干杯!!
这篇关于比较两种不同格式的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!