X days of the month.

Just starting out? Need help? Post your questions and find answers here.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

X days of the month.

Post 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
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
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: X days of the month.

Post by RSBasic »

Image
Image
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: X days of the month.

Post 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
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: X days of the month.

Post by davido »

@RSBasic,

Thank you for the date code.
Most instructive. :D
DE AA EB
Post Reply