Formula for Week# of Month

Kuih

New Member
Joined
May 24, 2005
Messages
29
Dear Excel gurus, what is the equivalent command to WEEKNUM if I want to properly calculate Week # of Month?

For example (Sunday being the first day of the week):
January 5th 2008 = Week 1 of January
January 6th 2008 = Week 2 of January
February 2nd 2008 = Week 1 of February
February 3rd 2008 = Week 2 of February

WEEKNUM perfectly calculates this, but it is applicable for the whole year.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I can't think of a built-in, or otherwise efficient way to get that result, but try this formula:

=SUMPRODUCT(--(DATE(YEAR(B12),MONTH(B12),ROW($1:$31))<=B12),--(WEEKDAY(DATE(YEAR(B12),MONTH(B12),ROW($1:$31)),1)=1))+1

Where B12 is where you have the date you want the week number for.
 
Last edited:
Upvote 0
Hi Kuih,
how do you define the first week of a month?
Is it the week containing the 1st day of the month or the first full week of the month?
 
Upvote 0
If it works like weeknum then the first of every month will be week 1 and week 2 will start on the next Sunday. Of course this means that some months will go up to week 6. To do that, with date in A1

=INT((DAY(A1)-2+WEEKDAY(A1-DAY(A1)+1))/7)+1
 
Upvote 0
Dear Arthur,

Thanks for your reply, the first day of the week is the week containing the 1st day of the month. As you know, WEEKNUM does take that into consideration and calculates it beautifully and you can specify the first day of the week can either be a Sunday (return value 1) or a Monday (2).

Dear barry and iliace,

Thanks for your solution, I will test your code right away.

However, the question is simple - rather than those lengthy codes, does anyone know a built-in formula that calculates this? If not, I wonder why Microsoft didn't include it in the first place...
 
Upvote 0
Hello Kuih,

No, there's no built in formula for this, I don't think it's that common to start from week 1 every month.

Try my suggestion, it isn't too complicated :)
 
Upvote 0
In my solution, to change the determining weekday from Sunday to any other weekday, simply change the portion highlighted in red below:

=SUMPRODUCT(--(DATE(YEAR(B12),MONTH(B12),ROW($1:$31))<=B12),--(WEEKDAY(DATE(YEAR(B12),MONTH(B12),ROW($1:$31)),1)=1))+1

=1 is sunday
=2 is monday
=3 is tuesday
etc...
=7 is saturday

I haven't examined Houdini's solution, but since his uses WEEKDAY() function also, I'm guessing you can do the same thing.
 
Upvote 0
Dear Barry and Iliace,

Thank you for your timely reply on this matter. Anyway, regarding your code;

Given by an example: March 2008 is a tricky one.

March 1st is a Saturday (not a working day)
March 3rd is a Monday (a working day and should be Week 1)
 
Upvote 0
That's not the functionality of WEEKNUM. Try WEEKNUM with Jan 1, 2011 and Jan 3, 2011 (identical to your example).

With the functionality you're requesting, what should the output be for March 1, 2008? Last week of February 2008? Week zero?
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,181
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top