Number of weekdays between two dates

deepheat101

Board Regular
Joined
Jul 26, 2006
Messages
138
Greetings Peeps...

Once again, I find myself with what seems to be a simple straight-forward task, and once again I find myself scratching my head struggling to find the answer (can't pull my hair out as there's none left after my last macro problem)

Given two valid dates how do I find the number of a specific weekday there are between the ranges?

For example,

fromDate = "1-May-2008"
toDate = "18-May-2008"
myWeekday = "Sunday"
theAnswer = 3

Many Thanks

dp
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Quoting Richard Schollar:

Requirement:
To determine the number of workdays between two dates. I know I could use NETWORKDAYS (note: requires Analysis Toolpak) eg:

Date in A1:
1st January 2008
Date in B1:
10th January 2008

=NETWORKDAYS(A1,B1)

to return 8 days, but what happens if my weekend days are actually Monday and Tuesday?

Solution:
=SUM(INT((WEEKDAY(A1-{1,4,5,6,7})-A1+B1)/7))

which returns 7. The number values within the array constant ie {1,4,5,6,7} sets which days are working week days based on their value returned by the Weekday function ie:

1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday

Hence to exclude Monday and Tuesday, the values 2 and 3 were omitted from the array constant {1,4,5,6,7}. To exclude Thursday and Friday you would use {1,2,3,4,7}. To exlcude Monday/Tuesday/Wednesday use {1,5,6,7} etc

Note this formula does not take into account holiday dates to exclude. If this is required use:

=SUMPRODUCT(ISNUMBER(MATCH(WEEKDAY(ROW(INDIRECT(A1 & ":" & B1))),{1,4,5,6,7},0))*ISNA(MATCH(ROW(INDIRECT(A1 & ":" & B1)),holidays,0)))

Where "holidays" is a single column defined name range on your worksheet which holds the holiday dates you wish to exclude (eg in C1:C3 say). Again, you use the array constant {1,4,5,6,7} to define which days you consider to be working days.
 
Upvote 0
I think the OP wants to know how many SUNDAYS there are between 5/1/2008 and 5/18/2008...

I'd like to know that one too...
 
Upvote 0
I think the OP wants to know how many SUNDAYS there are between 5/1/2008 and 5/18/2008...

I'd like to know that one too...

If you want Sundays only it would be:

Code:
=SUM(INT((WEEKDAY(A1-{1})-A1+B1)/7))

Taken from above where {1} represents Sunday.
 
Upvote 0
=SUM(INT((WEEKDAY(A1-{1})-A1+B1)/7))

That makes sense now, Thanks..
Here I went and wasted my time and made a VBA Custom UDF to do it..

=HowManyDays(A1,B1,1) - Weekday entered as a number 1=Sun, 2=Mon, etc..

Code:
Public Function HowManyDays(Sdate As Range, Edate As Range, Wday As Long)
Dim i
Dim MyCount As Long
For i = Sdate.Value To Edate.Value
    If Weekday(i) = Wday Then MyCount = MyCount + 1
Next i
HowManyDays = MyCount
End Function
 
Upvote 0
If you want Sundays only it would be:

Code:
=SUM(INT((WEEKDAY(A1-{1})-A1+B1)/7))

Taken from above where {1} represents Sunday.

Although, for a single day you don't need the SUM and you don't need the curly brackets, i.e. this will suffice

=INT((WEEKDAY(A1-1)+B1-A1)/7)
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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