Filtering data table with date condition

Am using for each loop to iterate the datatable and inside the for each loop am using if condition.
if the date is less than 2018-09-07, i need to write the data in workbook

Please help me with some workflow for above condition.

I Tried below attached method, but the value after the filter the (sheet2) seems to be wrong
TestWorkflowTemplate.xaml (10.4 KB) Data.xlsx (9.9 KB)

condition used in IF loop:

Datetime.ParseExact(Row(“Date”).ToString, “yyyy-mm-dd”, System.Globalization.CultureInfo.InvariantCulture)<Datetime.ParseExact(“2018-09-07”, “yyyy-mm-dd”, System.Globalization.CultureInfo.InvariantCulture)

Please find attached the solution. I have used a much simpler method.

For your method, if you ever want to transform a date to a string of a specific format you can use YourDateVariable.ToString(“dd-MM-yy hh:mm:ss”) - you can combine those as you want.

TestWorkflowTemplate.xaml (7.9 KB)

1 Like

Thanks much @bnastase.

I do have few doubts, i could see you have cloned the data table structure for the newly created Dt. Is that all necessary one? cant we simply initialize the datatable as new datatable in default option.

Also please help me to understand why am getting the false output value in my worklow, is there any logic failure

  1. If you want to use the add data row activity, specifically the Array Row property, you will need to have a structure to your table. When you create it from scratch it is a table will have no columns, rows. Clone will help you clone the structure of the table (it does not copy any information from the cloned table, only the structure).

  2. I think your condition works fine. The problem is your assign in the if with the select function - ExtractDataTable.Select("Type = ‘WI1’ ").CopyToDataTable.

Basically every time you find the right row, instead of copying the identified row with the right date over, you perform this select. This select will get all your WI1 rows(regardless of date) from your table and put it in new_DT, then you write it in Sheet2.

As a summary - For each row you find with the date<2018-09-07, you filter the entire table based on the WI1 filter and write it in sheet 2. The table just gets overwritten as many times as rows with the date<2018-08-07 you have.

Hope this makes sense.


1 Like

Thank you for clear explanation:)

1 Like

No problem :slight_smile:

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