Need to check if the datatable has same start date and end date

I need to check if the datatable has both start and end date is same if yes need to remove the row

For example:

My input

No. Start Date. End Date. Value

  1.         01/01/2023.     01/01/2023.    234
    
  2.         12/31/2022.      12/31/2022.    123
    
  3.         01/02/2024.       12/31/2024.    133
    

My output should be

No. Start Date. End Date. Value

  1.         01/02/2024.       12/31/2024.    133
    

Since first two row has same start and end date.so it should be removed

@sruthesanju

dt = dt.AsEnumerable().Where(Function(row) row.Field(Of DateTime)("StartDate") <> row.Field(Of DateTime)("EndDate")).CopyToDataTable()

Note: In my case row.Field(Of DateTime)(“StartDate”) is in datetime .In your excel it may be string please change the datatype as your requirement
Input:
image

OutPut

image

Hi @sruthesanju
Try below LINQ
Use assign activity
datatable variable = (From r In dt Where Not r(“StartDate”).ToString.equals(r(“EndDate”).ToString) Select r).CopyToDataTable

Hi @sruthesanju

→ Build Data Table
image
Output-> dt_Input
→ Use the below syntax in Assign:

dt_Input = dt_Input.AsEnumerable().Where(Function(row) row.Field(Of DateTime)("Start Date") <> row.Field(Of DateTime)("End Date")).CopyToDataTable()

→ Write Range Workbook
image

If your column datatype is System.String then you can use below syntax:

dt_Input = dt_Input.AsEnumerable().Where(Function(row) row.Field(Of String)("Start Date") <> row.Field(Of String)("End Date")).CopyToDataTable()

Hope it helps!!

Getting field is not member of Char

Hi @sruthesanju

Can you share your workflow?

or try this:

dt_Input = dt_Input.AsEnumerable().Where(Function(row) row.Field(Of String)("Start Date").ToString() <> row.Field(Of String)("End Date").ToString()).CopyToDataTable()

Regards

@sruthesanju

If yoy got any error please make a screenshot of it.

dt = dt.AsEnumerable().Where(Function(row) row.Field(Of DateTime)("StartDate") <> row.Field(Of DateTime)("EndDate")).CopyToDataTable()

In read range workbook please enable preserve format to true

Working now.thank you

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