Skip to main content
May 25, 2021
Question

Print mondays between given dates

  • May 25, 2021
  • 3 replies
  • 0 views

Hi,

How can we print dates on mondays between the given start date and end date?

Please provide the code for it.

For Example:

Input:

Start Date: 24/May/2021

End Date: 25 June/2021

output:

            31/May/2021 

            07/June/2021   

            14/June/2021

             21/June/2021

    3 replies

    ranjiths0003
    May 25, 2021

    Hi Ayushimittal,

    Use Below Code

    a!localVariables(
      local!days: getdatesbetweendate(ri!startdate, ri!enddate),
      index(
        local!days,
        wherecontains(2, apply(weekday(_), local!days))
      )
    )

    mikes0011
    Brainy
    May 25, 2021

    The above solution posted by Ranjith would work except I don't find the function "getDatesBetweenDate" anywhere - perhaps it's in a plug-in that I'm not familiar with.

    The following OOB code might be slightly more flexible and uses a!forEach instead of the index/whereContains combo, which can be a bit easier to read at least.

    a!localVariables(
      local!numDays: tointeger(ri!enddate - ri!startDate) + 1,
      local!dates: a!forEach(
        enumerate(local!numDays),
        ri!startDate + fv!item
      ),
      
      a!flatten(
        a!forEach(
          local!dates,
          if(
            text(fv!item, "dddd") <> "Monday",
            {},
            a!map(
              date: fv!item,
              day: text(fv!item, "dddd")
            )
          )
        )
      )
    )

    The Expression Guru
    csteward
    May 25, 2021

    I also like the weekday() function for comparing days of the week as integers.

    a!forEach(
      items: ri!startDate+enumerate(ri!endDate-ri!startDate+1),
      expression: if(weekday(fv!item)=2,fv!item,{})
    )