Filter by date using DataTable.RowFilter when ignoring time

How to filter records in a DataTable that are on a specific date?

I tried the simple [datecol] = #11 March 2010# and CONVERT([datecol],'System.DateTime') = #11 March 2010# . No luck.

MSDN: RowFilter Expression Syntax

Decision

 [datecol] >= #11 March 2010 00:00# AND [datecol] <= #11 March 2010 23:59:59# 
+4
source share
3 answers
 select ... ... ... where [datecol] between '11 March 2010 00:00:00' and '11 March 2010 23:59:59' 

Sorry, wrong. Just wrote a lot of SQL!

try it

 [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' 
+4
source
 select * from [X] WHERE DATEDIFF(dd,[datecol],'3/11/2010') = 0 

There are many features with a dated function,

DATEADD(DAY,DATEDIFF(DAY,0,[datecol]),0) is another way to remove the temporary part from a column if you need this data for other processing. We use this if we want to group elements that occur during the day, or any other uses if we need to group elements that occur within hours or after several hours.

+1
source

You can use the following LINQ code to filter the DataTable rowset by 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 an idea of ​​basic LINQ queries in DataTables, see Filtering DataTable Using LINQ

best rgds

+1
source

Source: https://habr.com/ru/post/1303831/


All Articles