Datatable select query on time field

Hi I have a column where i have some time in a column, i want to filter column ABC to only filter time between 1:00 and 2:00.
ABC
0:05
0:10
0:15
0:25
0:30
0:45
0:45
1:10
1:10
1:15
1:20
1:20
1:25
1:25
1:25
1:30
1:45
2:25
2:25
2:35

I am using datatable.Select("Convert([ABC],‘System.Int32’)>=1 AND Convert([ABC],‘System.Int32’)<=2 ").CopyToDataTable

But im getting no data found .

Any suggestions pls.

Hi,

1 - The value should be just greater and less than (1:00 and 2:00), or shoud be greater and equal or less and equal?

2 - Are your time variable in DateTime format? If no, make sure to change it (should be System.DateTime) before comparison.

datatable.Select(“abc >= 1:00 AND abc <= 2:00”).CopyToDataTable

In addition it might help u:

When current time is greater than fixed time,
DateTime.Now.TimeOfDay.CompareTo(fixedTime) outputs a 1

and when current time is less than fixed time,
DateTime.Now.TimeOfDay.CompareTo(fixedTime) outputs a -1

and when is equal
DateTime.Now.TimeOfDay.CompareTo(fixedTime) outputs a 0

Hi @ANSHUL
This query is not working

Thanks
Ashwin S

  1. Greater or equal to 1 and less than or equal to 2
  2. Data is read from excel sheet as shown above.

Thanks

@ANSHUL I created an example, take a look:

ExampleDateTimeTableComparison.xaml (6.7 KB)

1 - Create datatable (read excel range) and set “ABC” column as DateTime type
2 - Use select with your logical <=2:00 >=1:00