使用 DataTable.RowFilter 按日期过滤,同时忽略时间

发布于 2024-08-24 14:24:30 字数 429 浏览 5 评论 0原文

如何过滤数据表中特定日期的记录?

我尝试过简单的 [datecol] = #11 March 2010#CONVERT([datecol],'System.DateTime') = #11 March 2010#。没有运气。

MSDN:RowFilter 表达式语法

解决方案

[datecol] >= #11 March 2010 00:00# AND [datecol] <= #11 March 2010 23:59:59#

How do I filter for records on a DataTable which are on a certain date?

I've tried plain [datecol] = #11 March 2010# and CONVERT([datecol],'System.DateTime') = #11 March 2010#. With no luck.

MSDN: RowFilter Expression Syntax

Solution

[datecol] >= #11 March 2010 00:00# AND [datecol] <= #11 March 2010 23:59:59#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清眉祭 2024-08-31 14:24:30
select 
   ...
   ...
   ...

where [datecol] between '11 March 2010 00:00:00' and '11 March 2010 23:59:59'

抱歉,打错方向了。刚刚写了很多 SQL!

试试这个

[datecol] >= #03/11/2010 00:00:00# AND [datecol] <= #03/11/2010 23:59:59# 

 [datecol] >= '03/11/2010 00:00:00' AND [datecol] <= '03/11/2010 23:59:59' 
select 
   ...
   ...
   ...

where [datecol] between '11 March 2010 00:00:00' and '11 March 2010 23:59:59'

Sorry, wrong head on. Just been writing a LOT of SQL!!

Try this

[datecol] >= #03/11/2010 00:00:00# AND [datecol] <= #03/11/2010 23:59:59# 

or

 [datecol] >= '03/11/2010 00:00:00' AND [datecol] <= '03/11/2010 23:59:59' 
妄想挽回 2024-08-31 14:24:30
select * from [X] WHERE DATEDIFF(dd,[datecol],'3/11/2010') = 0

datediff 函数有很多功能,

DATEADD(DAY,DATEDIFF(DAY,0,[datecol]),0) 是另一种根据需要从列中删除时间部分的方法该数据用于其他处理。如果我们想要对白天发生的项目进行分组,则可以使用此选项;如果我们需要对几小时内或下班后发生的项目进行分组,则可以使用其他一些用途。

select * from [X] WHERE DATEDIFF(dd,[datecol],'3/11/2010') = 0

There is a lot of power with the datediff function,

DATEADD(DAY,DATEDIFF(DAY,0,[datecol]),0) is another way you can strip the time portion from the column if you need that data for other processing. We use this if we're wanting to group items that occur during the day, or some other uses if we need to group items that occur during hours or after hours.

野生奥特曼 2024-08-31 14:24:30

您可以使用以下 LINQ 代码根据日期过滤 DataTable 行集:

var resultSet = from tbl in dt.AsEnumerable()
                where tbl.Field<DateTime>("ColName").ToString("dd/MMM/yyyy") == "07/Aug/2010"
                select tbl;

此外,要深入了解 DataTable 上的基本 LINQ 查询,请参阅帖子 使用 LINQ 过滤 DataTable

最佳 Rgds

You can use following LINQ code to filter DataTable row-set according to date:

var resultSet = from tbl in dt.AsEnumerable()
                where tbl.Field<DateTime>("ColName").ToString("dd/MMM/yyyy") == "07/Aug/2010"
                select tbl;

Further, to get the insight of basic LINQ queries on DataTables see the post Filtering DataTable using LINQ

best Rgds

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文