Find All Weekends

이전달 중 토,일에 해당하는 일자를 모두 찾고싶다.
예시로 1월달이면 6,7,13,14,20,21,27,28 이렇게 숫자로 구하고 싶다
assgin로 찾는 방법을 알려줘 너무 어려워

Hello @wjdehdnr456
It is a working code:
BlankProcess62.zip (3.1 KB)

Solution which I used:

  1. Assign: currentDate = DateTime.Now
  2. Assign: firstDayPrevMonth = New DateTime(currentDate.Year, currentDate.Month - 1, 1)
  • If currentDate.Month = 1 (January), then firstDayPrevMonth = New DateTime(currentDate.Year - 1, 12, 1).
  • Otherwise, firstDayPrevMonth = New DateTime(currentDate.Year, currentDate.Month - 1, 1).
  1. Assign: lastDayPrevMonth = firstDayPrevMonth.AddMonths(1).AddDays(-1)
  2. Assign: nextDate = firstDayPrevMonth
  3. While Loop: nextDate <= lastDayPrevMonth
  • If: nextDate.DayOfWeek = DayOfWeek.Saturday Or nextDate.DayOfWeek = DayOfWeek.Sunday
    • Add to Collection: Add nextDate to the list of weekend dates
  • Assign: nextDate= nextDate.AddDays(1) (Increment date by one day)

Result:
image

2 Likes

Hi,

Can you try the following expression?

targetYear = 2024
targetMonth = 1

Then

arrDays = Enumerable.Range(1,DateTime.DaysInMonth(targetYear,targetMonth)).Where(Function(i) New DateTime(targetYear,targetMonth,i).DayOfWeek= DayOfWeek.Saturday OrElse New DateTime(targetYear,targetMonth,i).DayOfWeek= DayOfWeek.Sunday).ToArray()

If you need previous month, the following will help you.

targetYear =DateTime.Now.AddMonths(-1).Year
targetMonth = DateTime.Now.AddMonths(-1).Month

Sample
Sample20240108-1a.zip (2.7 KB)

Regards,

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.