Solved

Creating Excel date difference of week days only

Posted on 2007-04-10
10
230 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generating a graph via Excel 3 28
increment numbers by 10 11 31
Excel callender with date slider 5 29
how to re-acticvate Office 2010 6 29
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

863 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

18 Experts available now in Live!

Get 1:1 Help Now