Solved

Creating Excel date difference of week days only

Posted on 2007-04-10
10
231 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

821 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