Skip to main content
October 6, 2022
Solved

How to get Current month dates in a List?

  • October 6, 2022
  • 6 replies
  • 0 views

I want to filter out current month dates in a list 

"9/9/2022",

"9/8/2021",

"10/7/2022",

"9/29/2021",

"10/24/2022",

"7/19/2022",

"5/16/2022",

"8/15/2022",

"9/14/2022",

"10/14/2021",

"1/13/2022"

Expected result: {"10/7/2022","10/24/2022"}

Can somebody help me with this ?

      Best answer by harshitb6843

      a!localVariables(
        local!dates: {
          "9/9/2022",
          "9/8/2021",
          "10/7/2022",
          "9/29/2021",
          "10/24/2022",
          "7/19/2022",
          "5/16/2022",
          "8/15/2022",
          "9/14/2022",
          "10/14/2021",
          "1/13/2022"
        },
        local!month: month(today()),
        local!year: year(now()),
        a!forEach(
          items: local!dates,
          expression: if(
            like(fv!item, concat(local!month, "/*/", local!year)),
            fv!item,
            {}
          )
        )
      )

      6 replies

      harshitb6843
      October 6, 2022

      a!localVariables(
        local!dates: {
          "9/9/2022",
          "9/8/2021",
          "10/7/2022",
          "9/29/2021",
          "10/24/2022",
          "7/19/2022",
          "5/16/2022",
          "8/15/2022",
          "9/14/2022",
          "10/14/2021",
          "1/13/2022"
        },
        local!month: month(today()),
        local!year: year(now()),
        a!forEach(
          items: local!dates,
          expression: if(
            like(fv!item, concat(local!month, "/*/", local!year)),
            fv!item,
            {}
          )
        )
      )

      October 6, 2022

      Thanks a lot 

      stefanhelzle0001
      Brainy
      October 6, 2022

      We do not need to try to beat every problem with a foreach.

      a!localVariables(
        local!dates: {
          "9/9/2022",
          "9/8/2021",
          "10/7/2022",
          "9/29/2021",
          "10/24/2022",
          "7/19/2022",
          "5/16/2022",
          "8/15/2022",
          "9/14/2022",
          "10/14/2021",
          "1/13/2022"
        },
        index(
          local!dates,
          where(month(local!dates) = month(today()))
        )
      )

      sunilc0007
      October 6, 2022

      You can also try this:

      a!localVariables(
        local!dates: {
          "9/9/2022",
          "9/8/2021",
          "10/7/2022",
          "9/29/2021",
          "10/24/2022",
          "7/19/2022",
          "5/16/2022",
          "8/15/2022",
          "9/14/2022",
          "10/14/2021",
          "1/13/2022"
        },
        a!forEach(
          items: local!dates,
          expression: if(
            and(
              month(fv!item) = month(today()),
              year(fv!item) = year(today())
            ),
            fv!item,
            {}
          )
        )
      )