How to get week start date and end date for a given month and year

Certified Associate Developer

hi, 

I am looking to get the start date and end date for all weeks given a month and year. I am learning Appian, I could see some functions in documentation that needs a date. The other way i could think around is write a procedure in the backed and call it , which will add overhead. Any ideas or suggestion will help. 

  Discussion posts and replies are publicly visible

Parents
  • Just a quick solution, there could be other ways of doing this too.

    a!localVariables(
      local!year: 2024, 
      local!month: 8,
      /* Get the first and last day of the given month */
      local!firstDayOfMonth: date(local!year, local!month, 1),
      local!lastDayOfMonth: eomonth(local!firstDayOfMonth, 0), /* End of the month */
      local!result:a!forEach(
      items: enumerate(day(local!lastDayOfMonth)) + 1,
      expression: a!localVariables(
        local!currentDate: date(local!year, local!month, fv!item), /* Current day in the loop */
        local!weekStart:if(
          weekday(local!currentDate, 2) = 1, /* If the current day is Monday */
          local!currentDate, /* It's the start of the week */
          local!currentDate - weekday(local!currentDate, 2) + 1 /* Go back to the previous Monday */
        ),
        local!weekEnd: if(
          weekday(local!currentDate, 2) = 7, /* If the current day is Sunday */
          local!currentDate, /* It's the end of the week */
          local!currentDate + (7 - weekday(local!currentDate, 2)) /* Move forward to the upcoming Sunday */
        ),
        /* Handle boundary conditions if the start or end is outside the month */
        local!adjustedWeekStart: if(local!weekStart < local!firstDayOfMonth, local!firstDayOfMonth, local!weekStart),
        local!adjustedWeekEnd: if(local!weekEnd > local!lastDayOfMonth, local!lastDayOfMonth, local!weekEnd),
       /* Return the start and end date for the week */
        {
          start: local!adjustedWeekStart,
          end: local!adjustedWeekEnd
        }
      )
    ),
    union(local!result,local!result)
    )

  • 0
    Certified Associate Developer
    in reply to Soma

    thanks, i will try 

Reply Children