最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

比较两种不同格式的DateTime

SEO心得admin120浏览0评论
本文介绍了比较两种不同格式的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.

干杯!!

发布评论

评论列表(0)

  1. 暂无评论