Page 1 of 1
X days of the month.
Posted: Thu Jul 04, 2019 7:02 pm
by vwidmer
Is there a function or procedure or has any one written any code.
To be able to get X days in the month..
Example to be able to find all the Mondays in the month and which days they fall on?
Thanks
Re: X days of the month.
Posted: Thu Jul 04, 2019 7:07 pm
by RSBasic
Re: X days of the month.
Posted: Fri Jul 05, 2019 6:49 am
by Michael Vogel
You may check the date functions in the help file and play around a little bit to create your own functions...
Code: Select all
Procedure LastDayOfMonth(m,y)
ProcedureReturn 31-($441122)>>(m+m)&3-Bool(m=2 And (y&3 Or (y%100=0 And y%400)))
EndProcedure
Procedure CountDaysInMonth(weekday,m,y)
Protected last
last=LastDayOfMonth(m,y)
last-6+(6+weekday-DayOfWeek(Date(y,m,last,0,0,0)))%7
ProcedureReturn (last+6)/7
EndProcedure
Procedure FirstDayInMonth(weekday,m,y)
ProcedureReturn (weekday-DayOfWeek(Date(y,m,1,0,0,0))+7)%7+1
EndProcedure
Procedure.s Weekday(weekday)
ProcedureReturn Mid("SuMoTuWeThFrSa",weekday<<1+1,2)
EndProcedure
Procedure.s ListDays(first,number)
Protected s.s
While number
s+", "+Str(first)+"."
first+7
number-1
Wend
ProcedureReturn Mid(s,3)
EndProcedure
month=7
year=2019
For i=0 To 6
first=FirstDayInMonth(i,month,year)
count=CountDaysInMonth(i,month,year)
Debug Weekday(i)+": "+Str(count)+"x ("+ListDays(first,count)+")"
Next i
Re: X days of the month.
Posted: Fri Jul 05, 2019 1:09 pm
by davido
@
RSBasic,
Thank you for the date code.
Most instructive.