c# - LINQ 只选择今天当前时间之后的数据

标签 c# linq

我在使用 LINQ 查询时遇到问题 - 我正在使用它来选择一些飞行时间数据:

new XElement("Data",

                  from data in table
                  select new XElement("data", new XAttribute("data","data"),
                         new XElement("scheduledGateTime", data[1]),
                         new XElement("destinationCity", data[2]),
                         new XElement("flightNumber", data[3]),
                         new XElement("status", data[4]),
                         new XElement("terminal", data[4])

                         )
              )

我在过滤时遇到问题,在带来所有数据的那一刻,但我需要它只选择当“scheduledGateTime”在今天的当前时间之后。

比如gate时间是09:05,现在是13:10,我不想选这个..但是如果比赛时间是13:11,应该选。

我没有经常使用 LINQ,不知道该怎么做,有人可以帮忙吗?

谢谢

最佳答案

尝试这样的事情:

new XElement("Data",
              from data in table
              where DateTime.ParseExact(data[1], "dd/MM/yy HH:mm:ss", CultureInfo.CurrentCulture) > DateTime.Now
              select new XElement("data", new XAttribute("data","data"),
                     new XElement("scheduledGateTime", data[1]),
                     new XElement("destinationCity", data[2]),
                     new XElement("flightNumber", data[3]),
                     new XElement("status", data[4]),
                     new XElement("terminal", data[4])
                     )

您可能需要调整 DateTime 格式,我假设为“dd/MM/yy HH:mm:ss”。

关于c# - LINQ 只选择今天当前时间之后的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32396757/

相关文章:

c# - 添加到 List<MyClass> 时,SqlDataReader 不返回所有行

c# - 最小化的应用程序显示在任务栏上方

c# - 结束 else if 语句 C#

c# - 使用 LINQ 解析对象内部对象列表中的 Xml 对象

c# - 从一个 IList<> 中移除另一个 IList<> 中的项目

c# - 使用 LINQ 可以在不使用 foreach 的情况下突出显示 TreeNode 吗?

c# - ComponentMetaData.FireError 方法在 SSIS 脚本组件中的作用是什么

c# - 防止 Entity Framework 中循环导航属性的自动填充

c# - 我可以直接 "Extract"列表 <> 中的项目吗?

c# - msgpack 可以在 C# 中打包用户定义的对象,将包发送到 C++ 应用程序,然后在其中解包吗?