>>The application has to determine how many occurrences of a given day of the week occurred in a given calendar month.
>>
>>For example- How many Mondays (or any other specified day of the week) were there in February, 2016?
>>I can see how to get the answer by looping through all the days in the month in question, but is there a slicker way?
>
>
>* Sunday = 1, etc...
>
>CLEAR
>
>LOCAL Loop AS Integer
>
>FOR m.Loop = 1 TO 7
>
> ? m.Loop, WeekDaysInMonth(m.Loop,2016,10)
>
>ENDFOR
>
>
>FUNCTION WeekDaysInMonth (WeekDay AS Integer, CalendarYear AS Integer, CalendarMonth AS Integer) AS Integer
>
> LOCAL StartDay AS Date
> LOCAL FirstWeekDay AS Integer
> LOCAL ExtraDaysInMonth AS Date
> LOCAL Result AS Integer
>
> m.Result = 4
>
> m.StartDay = DATE(m.CalendarYear, m.CalendarMonth, 1)
> m.FirstWeekDay = DOW(m.StartDay)
> m.ExtraDaysInMonth = (GOMONTH(m.StartDay,1) - m.StartDay) - 28
>
> IF m.ExtraDaysInMonth > IIF(m.WeekDay < m.FirstWeekDay,m.WeekDay + 7 - m.FirstWeekDay,m.WeekDay - m.FirstWeekDay)
> m.Result = m.Result + 1
> ENDIF
>
> RETURN m.Result
>
>ENDFUNC
>
https://www.levelextreme.com/Home/ViewPage?Activator=1018&ID=1642130&LXMenu=2Thank you, Antonio
That looks pretty slick.
I'll try it.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.