### Thread: Current week number

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
Hi,

I am wondering if someone knows how I can split the month out into 5 weeks... then to have the week number printed and when the current week ends it will increment to the next week number. For example today is 3rd of July, therefore we are in week 1 of the month. Next week will be week two. I want it to go back to 1 at the start of the next month though. Can someone help me out with this one??? Thanks in advance.

Dave
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2000
Posts
45
Rep Power
18
Do you want to split the weeks up by Sundays or by every 7th day? You can do it either way, and I can help ya out with the code, but it would depend on which method you want...post a message telling me and i'll write the code.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
Finishing every sunday would be great - that is what i was thinking originally.

I did get an idea going but it is fudged a bit. I just used some if statements like...

if curdate is between 7 and 14 then set week to equal 2. I did that for the whole month but just changed what the value of the week would equal. But it is probably not a good way to do it. Thanks heaps for your help. Much appreciated.

Dave
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2000
Posts
45
Rep Power
18
aight, here's for every sunday (it's not that efficent but it gets it done)

\$curdate = date("j"); //gets current day (1-31) as string
\$current = strval(\$curdate); //convert to int
//same process for month and year

\$curmonth = date("n");
\$month = strval(\$curmonth);
\$curyear=date("Y");
\$year = strval(\$curyear);

\$week=1;
for(\$i=1;\$i<=\$current;\$i++)
{
\$day = date("D",mktime(12,0,0,\$month,\$i,\$year));
if(\$day=="Sun")
\$week++;
}

And that should give you the number of sundays (which is the same as the week #, plus 1) from the beginning of the month til the current date. Hope that works for ya.

5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
Thanks heaps polman, i think it works its a bit hard to tell because you can't really test out time, can ya? Anyway, thank you heaps and it seems I wasn't too far off with one of the ideas I had. But I never thought of checking to see what day it was and then incrementing the week. Thanks again, its much appreciated!!

Dave
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
hi again,

just one thing that concerned me a bit after looking at the code again... is the week going to reset back to 1 all the time?? Because wouldn't it only increment if the day is sunday? what if the day is sunday but the last one in the month (therefore the current week would be 4/5). If week is always resetting back to 1 then it wouldn't work would it. I may be wrong but I just wanted to be sure. Thanks.

Dave
7. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2000
Posts
45
Rep Power
18
Ok, I don't understand what you're talking about now. If yuo're given a date to find the week of, how can that date pass into another month? I don't understand how yuo could get into the next month. If you give me an example where it would then I can help you out but I don't know what you're talking about right now :-/
8. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
I don't mean pass into another month right now... I am just thinking say 3 weeks from now is the week value going to update (eg \$week=3)?? or is the part where \$week = 1 going to reset the \$week value back to 1 every time the page is loaded?? I want the value to keep incrementing as the weeks go by in the month but when a new month comes up it should go back to 1 again. So basically I am just counting the weeks in the current month. Hope this makes sense.

Dave.
9. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2000
Posts
45
Rep Power
18
Ok, this is what the loop is for. When the page loads, \$week will always equal 1, BEFORE the for loop. After the for loop runs \$week will be how many weeks have passed since the beginning. This will work for whatever month you're in and whichever date. The \$week will start out at 1 but will change by the end of the for loop. As long as this entire code is at the beginning of the page where you want the \$week variable, this will work (because \$week is updated in the for loop).

Hope that explained it to you.
10. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
Yep, got it now thanks again. I just wasn't sure if it recognised past sundays. I was worried that it might just recognise the current sunday and then increment it once. thanks for the explination, it makes it a lot clearer.

Dave!
11. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
Just a bit of a problem, I was thinking about it, and shouldn't my week value already equal 2?? I mean the 2nd of July was a Sunday, so really shouldn't week have incremented by 1? I can't seem to get it to increment at all by changing the day the it increments on, except if I set it to Thu it goes to 6!! And there hasn't been a Thursday in this month yet. Strange!

Dave
12. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2000
Posts
45
Rep Power
18
Hey, I don't know what the problem is man...I'll try running the script on debugging it...That script that I gave you SHOULD work, but then again alot of the code I write should work in theory. Lemme check it out and I'll get back to ya.
13. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
May 2000
Posts
77
Rep Power
19
polman, its cool, your code was perfect. i inadvertantly took out the year bit (as I thought I didn't need it) and it stuffed everything up. I put it all back in and it worked. I should never have doubted you buddy Thanks for the trouble you went to... and sorry for not getting back earlier, it has been a hectic afternoon!

Dave