Get Recent Date

My Studio Version: 2023.10.5
My Question: I have a datatable where I have 2 columns named Number and DateRange

I need to loop through datatable and should get the recent date among all those date values. Attached the picture below

My Solution : I tried with two solutions.

Solution 1 : Using DataTable

Step 1 : Build Data Table - With One Column Name (RecentDate) of Data type DateTime (System.DateTime) = Variable name is [dtInput]

Step 2 : Assign Activity - ExtractDataTable = new DataTable

Step 3: Read Range - Saved in Variable name called ExtractDataTable

Step 4 : Used For Each Row in DataTable activity
In Body - a) Assign Activity - strEndDate=Row(“DateRange”).ToString.Split({" - "},
StringSplitOptions.None)(1).Trim
//Above assign activity used to store the value from DateRange
column after the sign -
b) Assign Activity - ParsedEndDate = DateTime.Parse(strEndDate)
// ParsedEndDate is of variable type DateTime (System.DateTime)
c) Used AddDataRow activity to store ParsedEndDate value
Properties of activity - ArrayRow - {ParsedEndDate}
DataTable - dtInput
// I am getting error in this activity saying - Value of type ‘Date()’
cannot be converted to ‘Object()’ because ‘Date’ is not reference type
d) Assign activity - dtSorted (datatable) = dtInput.AsEnumerable().OrderByDescending(Function(r) CDate(r(“EndDate”))).CopyToDataTable()
e) Assign Activity - strRecentdate (String) = CDate(dtSorted.Rows(0)(“EndDate”))

Solution 2: Using List

Step 1 : Assign Activity - ListEndDates (List) = new List(Of DateTime)

Step 2 : Assign Activity - ExtractDataTable = new DataTable

Step 3: Read Range - Saved in Variable name called ExtractDataTable

Step 4 : Used For Each Row in DataTable activity
In Body - a) Assign Activity - strEndDate=Row(“DateRange”).ToString.Split({" - "},
StringSplitOptions.None)(1).Trim
//Above assign activity used to store the value from DateRange
column after the sign -
b) Assign Activity - ParsedEndDate = DateTime.Parse(strEndDate)
// ParsedEndDate is of variable type DateTime (System.DateTime)
c) If Activity - Condition = DateTime.TryParse(strEndDate,
ParsedEndDate)
//If Condition is True I am planning to add ParsedEndDate Value to List I
created.
My problem is I am unable to see activity named “Add To Collection” in Activity panel.
I have upgraded UiPath.System.Activities package to latest version.

Am I missing something If Yes how to add value to List which I created.

Need your help. TIA

Please let me know if you have queries in my question.

Hi,

Can you try the following expression?

New Object() {ParsedEndDate}

My problem is I am unable to see activity named “Add To Collection” in Activity panel.

AppendItemToList activity may help you.

Regards,

Hi @Ragala

Try with the activity Append Item to List instead of Add To Collection. First, create a variable of type List of DateTime and initialize it with New List(Of DateTime). Inside the For Each Row loop, use Append Item to List to add each parsed date. Set the list property to your list variable and the item to append property to the parsed date. After the loop, get the latest date using an assign activity with the expression MyList.Max().

happy Automation

Thanks Yoichi for the quick response

1 Like

Thanks Prashant for the solution

1 Like

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