It is currently Sun Dec 15, 2019 9:36 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: X days of the month.
PostPosted: Thu Jul 04, 2019 7:02 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jan 20, 2014 6:32 pm
Posts: 241
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


Top
 Profile  
Reply with quote  
 Post subject: Re: X days of the month.
PostPosted: Thu Jul 04, 2019 7:07 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1109
Location: Berlin (Germany)
Does this code help you? https://www.purebasic.fr/german/viewtop ... 16#p347716

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: X days of the month.
PostPosted: Fri Jul 05, 2019 6:49 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2460
You may check the date functions in the help file and play around a little bit to create your own functions...

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: X days of the month.
PostPosted: Fri Jul 05, 2019 1:09 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1715
Location: Uttoxeter, UK
@RSBasic,

Thank you for the date code.
Most instructive. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Kwai chang caine and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye