Take the freshest date from string


I have this stirng. And I want take the freshest date only( 2020-01-30) how?

@RPA3 first convert the following dates into list of DateTime then you can sort the list in descending fashion. Then the first item of the sorted list will be your recent date.

How I can do it?


To convert date string to date and time format use the below function


Use a for each activity to loop around each date and use add to collection activity to populate list(Of datetime) then use sort

I add in collection. How I can sort now?

Assumed you have a list of Datetime in place
Yourdatetimelist.OrderBy(function (x) x).Last()
Should Return the newest date

The freshest date not written at last, it maybe first or secon or last


Error ERROR Validation Error Compiler error(s) encountered processing expression “datesCol.OrderBy (function (x) x) .Last ()”.
Value of type ‘Date’ cannot be converted to ‘System.Collections.Generic.List(Of Date)’.

@RPA3 Can you share your xaml file? and can you tell us what is meant by Freshest Date according to you

Orderby is sorting Ascending, so we would expect oldest Date on First Position, newest on Last Position after sorting.

In Case of IT IS Not returning as expected then Debugging is recommended for further analysis

List should be of Datatype list(of Datetime)
The Datatype of the variable getting assigned by the Return of the Statement should not be a list, but from Datatype datetime

I didn’t understand. Could you send process, please?

Hello @RPA3

Try using this code

String.Split(","c).OrderBy(Function(r) cstr(r) ).last

use this code and let me know about it

1 Like

Hello @RPA3

Try the below code in uipath.

Thank you for your code @vickydas.it’s working.
getClosestDate.xaml (7.7 KB)

Hello! Thank you
It filter by date, then month and only then for years.
I have: 1

But I need the first date - 29.01.2020

I used this: «dateCol.OrderBy (function (x) x) .Last ()».

@RPA3 Can you tell me what is the Type of dateCol?

array of string

@RPA3 Can you use this instead and Check :
dateCol.OrderBy (function (x) CDate(x)).Max

Error: Write Line: Conversion from string “29.01.2020” to type ‘Date’ is not valid.

@RPA3 Will the Date be always in the Format dd.MM.yyyy ?