We want to Filter a DataTable with Column having Name “Instruction Date Time” with all data post 5 pm of date that is"27/01/2021 17:00:00". and other all data should be removed such as"27/01/2021 15:13:15". Kindly suggest us the logical flow for same.
You can use below linq, @Ripusudan_Sharma
Dt.AsEnumerable.Where(Function(x) x(“Instruction Date Time”).ToString.Trim.Contains(“17:00:00”)).CopyToDataTable()
Hope this may help you
Thank you for the Answer But we need to filter All Data Post “17:00:00” not the data with contains “17:00:00” and remove data which contains time before “17:00:00”. Can you suggest logic for same
Check this below query, @Ripusudan_Sharma
dt1.AsEnumerable.Where(Function(x) Cint(Split(Split(x(“Instruction Date Time”).ToString.Trim," “)(1).Trim,”:")(0)) >= 17 ).CopyToDataTable()
Hi. Does your column data type is String or DateTime?
In general, you can compare dates and datetimes without converting it to other datatypes. So, you can use something like this
dt.AsEnumerable.Where(Function (row) CDate(row("Col1")) > New DateTime(Now.Year, Now.Month, Now.Day, 17,0,0)).CopyToDataTable
column data type is string
Thank you @Manish540 For the solution
@Manish540 can you please modify your query and for condition to keep all data between “17:00:00” and “17:30:00” Only. Kindly provide solution for this
dt.AsEnumerable.Where(Function (row) (DateTime.ParseExact(row("Col1").ToString,"dd/MM/yyyy HH:mm:ss", Nothing) > New DateTime(Now.Year, Now.Month, Now.Day, 17,0,0)) And (DateTime.ParseExact(row("Col1").ToString,"dd/MM/yyyy HH:mm:ss", Nothing) < New DateTime(Now.Year, Now.Month, Now.Day, 17,30,0))).CopyToDataTable
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.