After much frustration with this decided to try Python:
import datetime
def date_by_adding_business_days(from_date, add_days):
business_days_to_add = add_days
current_date = from_date
while business_days_to_add > 0:
current_date += datetime.timedelta(days=1)
weekday = current_date.weekday()
if weekday >= 5: # sunday = 6
continue
business_days_to_add -= 1
return current_date
Same setup as with the VB script: Open a session, either use a script file or manual input, call the date_by_adding_business_days and pass in the params. ‘bot error’ returns
@JMarino you have to consider input as array when passing list from AA.
In your VbScript change function parameter as:
Function AddWorkingDays (arguments)
startDate = CDate (arguments(0))
workingDays = arguments(1)
I’ll give this a try today and let you know.
@Sumit.K11 This still doesn’t work.
I tried something as simple as this just to see if I can feed in params and get something out.:
Public Function WorkingDaysFromToday(arguments) As String
startDate = CDate (arguments(0))
workingDays = arguments(1)
WorkingDaysFromToday = workingDays
End Function
I still get ‘bot error’
I’m assigning a date as string to a list variable (this should be row 0) and then assigning the number 5 to the same list variable (row 1). Same setup as in my screenshot above. Same results.
@Sumit.K11 I finally got it to work using the following script:
Public Function WorkingDaysFromToday(arguments)
startDate = cdate(arguments(0))
DayCount = 0
workingDayCount = 0
maxCount = cint(arguments(1))
Do Until workingDayCount = maxCount
If Not (Weekday(DateAdd("d", DayCount, startDate)) = 1 Or Weekday(DateAdd("d", DayCount, startDate)) = 7) Then
workingDayCount = workingDayCount + 1 ' It's a working day!
End If
' Keep count of the total number of days needed to make up the working day target
DayCount = DayCount + 1
Loop
DaysFromToday = DateAdd("d", DayCount - 1, startDate) ' Subtract 1 day to get the correct date
WorkingDaysFromToday = DaysFromToday
End Function
I’d still like to get some error trapping in there.
@Sumit.K11 I clicked on the wrong link. Sorry you did not get credit for helping solve this!