Skip to main content
Inspiring
Feb 15, 2021 4:16 PM UTC
Solved

Extract work days only from data range

Hello, 

I would like how to formulate string which can be foreached after with only working dates between two dates. 

Lets say if I have 

start date: 2021-02-15 19:11:43

end date: 2021-02-22 19:11:43

In this case the result have to be {2021-02-15, 2021-02-16, 2021-02-17, 2021-02-18, 2021-02-19, 2021-02-22}

Any ideas how this can be achieved ?

    mikes0011
    mikes0011Answer
    Brainy
    Feb 15, 2021 4:32 PM UTC

    As usual, a!forEach() saves the day...

    a!localVariables(
      
      local!date1: today(),
      local!date2: today() + 8,  /* these 2 are hardcoded just for example sake */
      
      local!dateSpan: tointeger(local!date2 - local!date1), /* get the number of days difference between the 2 dates (8) */
      
      a!forEach(
        items: enumerate(local!dateSpan+1), /* get a list of {0 ... N} where N = the total number of days */
        
        expression: local!date1 + fv!item /* start date + 0, start date + 1, ... start date + N */
      )
    )

    The Expression Guru

    3 replies

    mikes0011
    mikes0011Answer
    Brainy
    Feb 15, 2021 4:32 PM UTC

    As usual, a!forEach() saves the day...

    a!localVariables(
      
      local!date1: today(),
      local!date2: today() + 8,  /* these 2 are hardcoded just for example sake */
      
      local!dateSpan: tointeger(local!date2 - local!date1), /* get the number of days difference between the 2 dates (8) */
      
      a!forEach(
        items: enumerate(local!dateSpan+1), /* get a list of {0 ... N} where N = the total number of days */
        
        expression: local!date1 + fv!item /* start date + 0, start date + 1, ... start date + N */
      )
    )

    The Expression Guru
    Inspiring
    Feb 15, 2021 4:42 PM UTC

    This is exactly what is needed with one exception. That in the final array should appears only workdays

    mikes0011
    Brainy
    Feb 15, 2021 4:44 PM UTC

    The a!forEach expression is flexible luckily and you can simply add logic to test whether the date generated within each member of the loop is a workday.  I believe you would just use the calIsWorkDay() function for this.

    The Expression Guru