Find All Weekends

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