Find Highest date

Hi guys,
i am fetching data from datatable in string format and its like ps1=“2019-05-08”
ps2=“2019-05-11” ps3=“2019-08-02” i.e yyyy-MM-dd
Although these are dates but they have been saved in string format
now i want the bot to extract the highest date among these and sometimes it can be 3 fields or 2 fields or 1 or 5 fields so among them it has to pick highest date like over her it is “2019-08-02”
how can it be done considering that there can be ps1 and ps2
or ps1,ps2,ps3

Hi Somya,

From your process is it possible to figure out how many number of string variables you will be getting?

It may be 2,3 or 4

In this format you can just sort them as string and get the bigger one

Can u provide with the xaml…as it also depends if any of these string are present or not

If they are blank strings, they still can be sorted. Check this if it solves your problem

Main.xaml (7.9 KB)

1 Like

here in the example you have used build datatable activity and input dialog from which you are taking dates and storing in build datable activity output variable but in my case bot will be reading date string directly from datatabase.
i have used foreach loop and inside that assign variables to assign values coming from database.Now the sorting needs to be done on them.
So do i need to use Builddatatable activity in that case also?

Hi @somya177,

1. Initialize first your variable
lSortedDateTime as List set the default value as new List(Of DateTime)
myDateTime as DateTime
lMyDate as List set the default value as new List(Of DateTime)
MyString = “2019-09-28”
MyString = “2017-09-28”
2. Transform and Add to List
2.1. on you assign activity:
myDateTime = DateTime.ParseExact([Your String], “yyyy-MM-dd”,Nothing);


2.2. Use Invoke Activity:

3. Sort using Assign Activity: (NOTE: I just put the sort on my assign activity to make sure everything is sorted but once you add an item to your List it will automatically sort by ASC order by default, incase we make sure everything is intact)

lSortedDateTime = lMyDate.OrderBy(Function(o) o.Date).ToList

4. Assign to your string [MyFirstDate]
MyFirstDate = lSortedDateTime.First.ToString("yyyy-MM-dd)

Final xaml:
Test.xaml (8.3 KB)
Best Regards,
Jeven

Apologies @somya177 ,

If you’re looking for the latest date just change the value of First to Last:

  • First - earliest date
  • Last - latest date

On step #4
MyFirstDate = lSortedDateTime.Last.ToString("yyyy-MM-dd)

Best Regards,
Jeven

1 Like