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
X days of the month.
X days of the month.
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: X days of the month.
Does this code help you? https://www.purebasic.fr/german/viewtop ... 16#p347716
- Michael Vogel
- Addict
- Posts: 2677
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: X days of the month.
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