Search code examples
weekdayautomationanywhere

How to get / output all days in the current week in Automation Anywhere?


I'm attempting to output all days within the current week. e.g. for this week, show all days, 05/12/2019 through 05/18/2019 only. when the bot is executed next week, only show days 05/19/2019 through 05/25/2019. My current logic outputs the days for this week, but come tomorrow, the dates for this week will be thrown off. Please see the following

enter image description here

...could I get some help with this please?


Solution

  • Using VBS

    I would do this using a VBS script, using Run Script command.

    The default week start is Sunday you can change it check: https://www.w3schools.com/asp/func_weekday.asp

    Pass the day you that you want as a parameter from 0 to 6, and get the data as a return value.

    DayNumber: 0 = Sunday ..... 6 = Saturday

    InputDate = Date
    DayNumber = WScript.Arguments.Item(0)
    Result = DateAdd("d", DayNumber - WeekDay(InputDate, 2), InputDate)
    WScript.StdOut.Write(Result)
    'MsgBox(Result)
    

    Using MetaBot

    Metabot Link: Change Date and Time Format

    You will have to run the following logic in sequence.

    Input: DayNumber: 0 = Sunday ..... 6 = Saturday

    1. Using DayOfWeek Logic, Get the Day of the week and assign it to WeekDay variable, it will return the name, not the number, and the input will be Date.
    2. Using IF conditions convert the name of the day to number, start from 0 to 6 as your first day in the week, which is Sunday, and using variable operation assigns the value to NumWeekDay variable.
    3. Using variable operation, Get the offset by subtracting DayNumber, the day you want minus NumWeekDay, and assign the value to Offset variable.
    4. Using AddDays, Input the date and the offset, and you will get the date of the day that you want.

    enter image description here