Jump to content

Number of Weeks


maxudaskin

Recommended Posts

I know it is possible (in some way) to figure out the number of weeks in a month, but not in the way you are probably thinking. What I want to do is make a calendar for my website. I don't want to use a pre-made script because I want (I want a lot of things :P) to make my whole site integrated and have it look good together.

 

I want to be able to figure out how many weeks a month falls under if a week is:

 

Sun, Mon, Tue, Wed, Thu, Fri, Sat

 

If a month was to start on a Thursday and last 31 days, then it would have 5 weeks as illustrated below.

 

   Sun, Mon, Tue, Wed, Thu, Fri, Sat
1:                      1    2    3
2:  5    6    7    8    9   10   11
3: 12   13   14   15   16   17   18
4: 19   20   21   22   23   24   25
5: 26   27   28   29   30   31

Link to comment
https://forums.phpfreaks.com/topic/112283-number-of-weeks/
Share on other sites

If you have the code already to produce the table you have in your post, could you not just have a counter variable that is initialised to 0 and increment each time you echo a new table row. This would then at the end hold the number of weeks in the given month. If for some reason you wanted this value before you echo the calender table you could simply store the table in a variable untill ready for echoing.

Link to comment
https://forums.phpfreaks.com/topic/112283-number-of-weeks/#findComment-576466
Share on other sites

I know that I should be shot for saying this, but honestly I think it would be easier to just hardcode it into an array.  I mean, 12 elements has you covered for the next year...just pick up a calendar and count.  I mean, I really don't see a reason for making a code recalculate something like this every single page load...

 

 

Link to comment
https://forums.phpfreaks.com/topic/112283-number-of-weeks/#findComment-576472
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.