You can find the difference between the StartDate and the EndDate and save this as an integer I’ll call TotalDays. Then Use a for each loop for each day in Enumerable.Range(0,TotalDays). Now if you want to loop from oldest date to newest you’d do StartDate.AddDays(day) and if you wanted to loop from newest back to oldest date you’d use EndDate.AddDays(-day)
This is very helpful, thank you. What variable types did you use for the startDate and endDate? I also got errors for the Log message because it won’t let a conversion from string to integer occur. How can I remedy this?
@TasneemA
Both dates are System.DateTime types. Then I’m logging "Do something with " + startDate.ToString("yyMM") + "." which is just three strings concatenated together. I think fixing the variable type will also fix your conversion error, since the log output should work fine as is.
If you are adding an unknown amount you should add it to a list rather than an array because you can add/remove items from a list, but you can’t do that to an array (you have to resize it instead, which is much slower).
You can add items to a list by using the activity called “add to collection”
@Dave I added the add to collection activity and created a variable to store it call AccPeriod. In the Properties panel, I put AccPeriod in the Collection field. I am getting the error: “Complier error(s) encountered processing expression “AccPeriod”. Value of type ‘Date’ cannot be converted to 'System.Collections.Generic.ICollection(Of Object)”.
@happygal321 The properties for the ‘Add To Collection’ activity should be as follows:
Collection: This is the list you are using. It should be a list of system.DateTime - it looks like you named it AccPeriod Item: This is the datetime variable you want to add to your list. TypeArgument: Make sure this is System.DateTime
Here is a screenshot showing an example where I have a list of datetime variables called “MyList” and am adding the current datetime to this list.
@Dave I changed my variable AccPeriod to of type List and enter that in the properties panel in Collections. But now i get the error “Complier error(s) encountered processing expression “AccPeriod”. Option Strict On disallow implicit conversions from ‘System.Collections.Generic.List(Of Date)’ to ‘System.Collections.Generic.ICollection(Of System.Collections.Generic.List(Of Date))’.”
@happygal321 please double check that you have updated all the properties as shown in the screenshot and listed in my last response. If everything is the same, please delete the activity and try again as sometimes UiPath has trouble when you change variable types like that
Will this work for going forward through dates as well? I am trying to get it to run through dates on the calendar. I am working with TeamUp calendar which works like Google calendar but it just won’t run at all. I’m trying to figure out what is wrong with my automation.
Yes just reverse the order. Currently it is using .AddMonths(-1). Go ahead and change it so it is .AddMonths(1) instead and switch the sign so it is startdate <= enddate