使用 LINQ 从列中获取各个日期的最佳方法
我在一个 MSSQL 表列中有以下数据
2011-06-20 11:53:32.000
2011-06-20 11:54:24.000
2011-06-20 11:55:45.000
2011-08-05 10:24:12.000
2011-08-05 10:25:28.000
2011-08-05 10:26:20.000
2011-08-05 10:27:12.000
2011-08-05 10:28:04.000
2011-08-05 10:28:55.000
使用 LINQ,我想从该列中获取以下数据
2011-06-20
2011-08-05
所以我可以将其放入 List<> 中
最好的方法是什么?我已经设置了上下文内容,所以我不需要这方面的详细信息。我只需要了解可以用来获取这些数据的最佳“查询”和逻辑。谢谢!
I have the following data in one MSSQL Table column
2011-06-20 11:53:32.000
2011-06-20 11:54:24.000
2011-06-20 11:55:45.000
2011-08-05 10:24:12.000
2011-08-05 10:25:28.000
2011-08-05 10:26:20.000
2011-08-05 10:27:12.000
2011-08-05 10:28:04.000
2011-08-05 10:28:55.000
Using LINQ, I would like to get the following data from the column
2011-06-20
2011-08-05
So I can put into a List<>
What's the best way to do this? I already have the context stuff setup, so I don't need details on that. I just need an idea of the best "query" and logic I can use to get this data. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在查找一系列日期时间中的所有不同日期,下面将显示示例来获取您需要的内容,前提是您已经将它们放在字符串中或通过查询数据库来获取:
示例(包含字符串列表) :
示例(来自数据库表):
演示功能的控制台示例:
You are looking for all of the Distinct dates in a range of DateTimes, the following will show examples to get what you need, given you already have them in a string or by querying your database:
Example (with list of strings):
Example (from database table):
Console Example to demonstrate functionality:
要在列表中选择不同的日期,请尝试以下操作:
To select distinct dates into a list try this: