How to select datarow based on most recent date

Hello,

I have an issue when I want to select a datarow from a “build data table” activity.
I buil a data table with 2 columns : Date(string) and Price(string)

I get information from a MainFrame : Date and Price
I store them into string variables : Date1, Price1, Date2, Price 2, and so on…
date output is for example : 03.09.2018 etc
I have had Add Data Row to put the variables into the datatable

Then I need to choose only the price with the most recent date.

I tryied this formula :
Assign : str_RecentDate : dt_DatePv.AsEnumerable.Select(Function ( r ) r(1).toString.Trim).OrderBy(Function (s) DateTime.ParseExact(s, “dd.MM.yyyy”, System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)).Last()

But I have an error message :
Assign : The string was not recognized as a valid DateTime.

Can anyone see where is my mistake please ?

Thank you !

@najoua.abbaci
for any reasons a string is sent to the datetime,parseexact that is not in the expected format. Here a debugging is helping for inspecting the content of the datatable.

For reference on the implementation have a look here:
GetRecentDateFromDataTable.xaml (6.7 KB)

Thank you for your answer and i just tryied with your formula but return me the same error message :confused:

your statement looks ok on the first look. It could be about the data which you send to the parseExact.
What is the content of the datatable?

Also have a look here on a demo case for filtering the non parseable date strings out into a list:
FindNotMatchingDateFormatDates.xaml (6.8 KB)

1 Like

I’m sorry if my answer is not what you expect, coz i’m a rookie in UiPath (and in dev)
I have two columns in my datatbale : one : Date(stringtype), another one : Price (string)
I collect the information from a MainFrame with Get text and the result return a string.

the FindNotMatchingDateFormatDates seems to work because i don’t have any error message.
But How can I check if it is the right date ?
Can you please tell me what should i put on the Write line or Log message to got it ?

Thank you very much for your help !

@najoua.abbaci
if the first column in datatable is the datecolumn then try following:

dt_DatePv.AsEnumerable.Select(Function ( r ) r( 0 ).toString.Trim).OrderBy(Function (s) DateTime.ParseExact(s, “dd.MM.yyyy”, System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)).Last()

the column indexes are 0 based or just use the columnname

1 Like

I replace with this and now i don’t have any error message, so THANK YOU.

Sorry but can you help me with another issue.
Now that I find the recent date in my datatable, i need to store in a variable the price link to this date.
My dt_DatePv is like this
Date1, PV
01.03.2010, 0.45
04.08.2020, 1.45
etc etc
I need to select the price with the most recent date.

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