Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Number of Mondays in a month
Message
De
20/10/2016 07:26:30
 
 
À
20/10/2016 02:42:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01642129
Message ID:
01642139
Vues:
56
>>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=1021&ID=1642130&LXMenu=2
Thank you, Antonio
That looks pretty slick.
I'll try it.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform