Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.