比较两种不同格式的DateTime

编程入门 行业动态 更新时间:2024-10-13 04:26:00
本文介绍了比较两种不同格式的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

本文发布于:2023-11-30 16:01:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650611.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   格式   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!