Linq Query to Filter Datatable column as same date with 2 hrs time.? Pls

Conditions

  1. If Purchase Date are within the same day & they are within 2 hours
  2. Amount should be more than 2 $
Input
ID Purchase Date Amount
0002 2021/04/01 08:13:00 2
0173 2021/03/29 13:52:00 65.86
0173 2021/04/01 13:23:00 47.68
0173 2021/04/01 15:22:00 74.72
0250 2021/03/29 10:46:00 70.02
0250 2021/03/31 11:33:00 46.03
0272 2021/04/01 09:45:00 36.03
0272 2021/04/01 09:45:00 10.5
Output
ID Purchase Date Amount
0173 2021/04/01 13:23:00 47.68
0173 2021/04/01 15:22:00 74.72
0272 2021/04/01 09:45:00 36.03
0272 2021/04/01 09:45:00 10.5

@Santhosh_Hyd I have saw your post regarding date comparison is possible to help me in this scenario. Thanks

Hi @Aravinthan

You can try this

Consider read the excel and store in dt1

Now use below linq query

dt1= dt1.AsEnumerable().Where(Function(row)
DateDiff(DateInterval.Hour, CDate(Now.ToString(“yyyy/MM/dd HH:mm:ss”)),CDate(row(“Purchase Date”)))<=2 And Cint(row(“Amount”))>2). CopyToDataTable

2 Likes

The query works fine but I need the output based on repeating date also shown in Output window . could you please help me . The code you gave takes all the repeating value based on date

Hi @Aravinthan
i am not cleared with question could you elaborate it please?

For eg if you take Input ID 0173 it has 3 rows but we need to filter and get Output based on repeating Purchase Date on same day and they are with in 2 hrs and amount less than 2$ so output will be only two rows for ID 0173

Output
|0173|2021/04/01 13:23:00|47.68|
|0173|2021/04/01 15:22:00|74.72|

Hi @Aravinthan
did u need to compare the purchese date with today’s date ?

not with todays date bro have to check and get those duplicate dates occurred in Purchase Date
with time diff of 2hrs time

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