Solved

Creating Excel date difference of week days only

Posted on 2007-04-10
10
229 Views
Last Modified: 2010-05-18
I'm looking to make an Excel formula that takes the difference of two dates, skipping weekends.  I want only weekdays, but the standard subtraction formula counts all calendar days.

How can i do this without installing a third-party add-in?  THanks
0
Comment
Question by:bdietz
  • 3
  • 3
10 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 18885539
The formula below returns the number of specific week days between any two dates. The week days to count are specified as an array enclosed in braces. The week days are integers where 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, and 7 = Saturday. The example formula below counts the number of week days (Monday through Friday) between the two dates.

   =SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&B1)))={2,3,4,5,6})*1)

The example formula below counts all Mondays between the dates in A1 and B1.

   =SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&B1)))=2)*1)

The two dates do not have to be in any order. If only one week day is specified the braces are not required. Dates that can be used range from January 1, 1900 to June 5, 2079.

To consider holidays, use the formula template below.

   =SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&B1)))={2,3,4,5})*(COUNTIF(X1:X10,ROW(INDIRECT(A1&":"&B1)))=0))

Where the range X1:X10 is a list of holidays specified as Excel date time values. Only week days that do not fall on the specified list of holidays are counted.

Kevin
0
 
LVL 5

Expert Comment

by:Michael V Bernot
ID: 18885758
There is also a function that requires the Analysis Toolpak add-in (Tools - Add-Ins check Analysis Toolpak) called NETWORKDAYS.  

=NETWORKDAYS(startDate, EndDate)

You can also add a comma after the end date and include the list of Holidays (range of cells) you would also like to exclude.  Good Luck.

MVB

0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18885782
A word of caution: NETWORKDAYS requires a reference to the Analysis ToolPak.

Kevin
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:bdietz
ID: 18890370
Thanks.

For formula

 =SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&B1)))=2)*1)

Works if cells A1 and B1 contains dates.  However, follow up:  I want to compare cell A1 to the current date.  I tried NOW() in place of B1 and i get a #REF!.  I also tried DATEVALUE(NOW()) and i get #VALUE!.

Can you help?  Thanks
0
 
LVL 5

Expert Comment

by:Michael V Bernot
ID: 18890390
Bdietz,

Try today().

MVB
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18892165
Note that the formula you chose only counts Mondays. If you want to count week days (Mon-Fri) then use:

=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&B1)))={2,3,4,5,6})*1)

The formula requires integer values for the dates (no time component) so you can truncate the value:

TRUNC(B1)

you can truncate the NOW function result:

TRUNC(NOW)

or you can use the TODAY function as MVB stated.

Excel stores dates as double values where the whole part of the number of the day and the fractional part is the time.

Kevin
0
 
LVL 5

Expert Comment

by:Michael V Bernot
ID: 19053538
Daleoran,
    Kevin's solution is one that I've added to my KNOWLEDGE BASE.  It's a unique way to use the INDIRECT function to turn the date input into a range!  It does not require the ANALYSIS TOOL-PAK, but is a little more involved than the built in NETWORKDAYS function that can be accessed with the ADD-IN.
    Both solutions do provide a different way to arrive at the same answer to the question.  That being said, any recommedation you make would be fine with me!

Michael

   
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now