FIlter datatable by time

hi, i have an excel column contains datetime (“yyMMddHHmm”)in string, what i am trying to is filter my datatable by time(“HHmm”), for an example remove all data higher than 4:30 PM which is (yyMMdd1630). can someone help me out?
image

Hey

can you try with the following code?

dtResult.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("DATE_TIME").ToString(), "yyMMddHHmm", CultureInfo.InvariantCulture).TimeOfDay <= New TimeSpan(16, 30, 0)).CopyToDataTable()

Regards

i have this error sir

Hey

Please check
Main.xaml (12.3 KB)

solved sir, thanks for your help

1 Like

one more thing sir, can you let me know please how to select data from 16:30 till 21:00?

Hey

check this

dtResult.AsEnumerable().Where(Function(row) DateTime.ParseExact(row("DATE_TIME").ToString(), "yyMMddHHmm", CultureInfo.InvariantCulture).TimeOfDay >= New TimeSpan(16, 30, 0) And DateTime.ParseExact(row("DATE_TIME").ToString(), "yyMMddHHmm", CultureInfo.InvariantCulture).TimeOfDay <= New TimeSpan(21, 0, 0)).CopyToDataTable()

Regards

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.