How to assign value in datetime list variable

Hi Expert
I need your help how to pass multiple date in date time list variable
new List(of DateTime) from {new Datetime(2018,12,30)}
I have these value which I need to assign in datetime list variable and sort that.
4/5/2022 1:02 PM
4/5/2022 3:39 PM
4/5/2022 3:28 PM
4/5/2022 1:15 PM``

Hi @Aleem_Khan,

You can assign multiple datetime to list with this code.

listDates = new List(of DateTime) from {new Datetime(2018,12,30),new Datetime(2018,10,20),new Datetime(2018,11,30)}


1 Like

Hi @Aleem_Khan

  1. Use Assign activity
ListVale = new List(of DateTime)
  1. Use Assign activity
Date1 = new Datetime(2018,12,30)
  1. Use Append Item to List activity

  2. Log message → To print all the values in the List




And you can sort them by ascending with this assign.

listDates = listDates.OrderBy(Function(x) DateTime.ParseExact(x.ToString,"MM/dd/yyyy hh:mm:ss",Nothing,Nothing)).ToList


1 Like

Hi @Aleem_Khan find the below code

sequence (2).zip (1.6 KB)

@Aleem_Khan this for sort

DateTimeList.OrderBy(function(x) x)

String.join(","DateTimeList.OrderBy(function(x) x),)

1 Like

how to pass time also

4/5/2022 1:02 PM

HI @Aleem_Khan

Try like this

New List(of DateTime) From{DateTime.ParseExact("4/5/2022 1:02 PM","d/M/yyyy h:mm tt",nothing),DateTime.ParseExact("4/5/2022 3:39 PM","d/M/yyyy h:mm tt",nothing),DateTime.ParseExact("4/5/2022 3:28 PM","d/M/yyyy h:mm tt",nothing),DateTime.ParseExact("4/5/2022 1:15 PM","d/M/yyyy h:mm tt",nothing)}

To sort use this

String.Join(",",list.OrderBy(Function(s) s))

Hope this helps


1 Like

Hi @Aleem_Khan,

If you have these values already in the form of Collection/Datatable. Then we could use that collection to directly convert to List Of DateTime.

Let’s Consider, the input dates are in a Array String, then we could do the Conversion as below :

datesList = strDates.Select(Function(x)DateTime.ParseExact(x,"M/d/yyyy h:mm tt",System.Globalization.CultureInfo.InvariantCulture)).ToList

Here, datesList is a variable of the type List(Of DateTime) and strDates is a variable of the type Array of String or List(Of String).

Let us know if you still need further help or if received any errors.

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