Skip to main content
Inspiring
February 15, 2021
Solved

Extract work days only from data range

  • February 15, 2021
  • 3 replies
  • 0 views

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 ?

    Best answer by mikes0011

    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 */
      )
    )

    3 replies

    mikes0011
    mikes0011Answer
    Brainy
    February 15, 2021

    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
    February 15, 2021

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

    mikes0011
    Brainy
    February 15, 2021

    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