Calculation query

Tanya Addison

New Member
Joined
Jul 10, 2003
Messages
45
Can I run a calculation query that brings back the number of working days between two dates?

I have tried DateDiff with little success

Thanks

T
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Microsoft Knowledge Base has a Work_Days function,
Article ID: Q97757

Here is the function:
Code:
'-------------------------------------------------------------------
' Function:   WorkDays()
' Purpose:    Calculate the number of working days between two dates.
'             Includes the start date and the end date; so, the number of days
'             between 02/02/93 and 02/03/93 equals one. 
'             Note: This function does not account for holidays.
'             To call the function, you can pass either a valid string or an
'             actual date value:
'             WorkDays("01/01/93", "12/31/96"), returns 1042.
'             WorkDays("#03/05/93#, #04/06/93#), returns 22.
' Parameters: varBegDate - Beginning date.
'             varEndDate - Ending date.
' Returns:    The number of working days between two dates.
'-------------------------------------------------------------------
Function WorkDays(varBegDate As Variant, varEndDate As Variant) As Integer
   On Error GoTo HandleErrors
   
   Dim varWholeWeeks As Variant
   Dim varDateCnt As Variant
   Dim intEndDays As Integer
   
   On Error GoTo HandleErrors
   
   varBegDate = DateValue(varBegDate)
   varEndDate = DateValue(varEndDate)
   varWholeWeeks = DateDiff("w", varBegDate, varEndDate)
   varDateCnt = DateAdd("ww", varWholeWeeks, varBegDate)
   intEndDays = 0
   Do While varDateCnt < varEndDate
       If Format(varDateCnt, "ddd") <> "Sun" And _
          Format(varDateCnt, "ddd") <> "Sat" Then
          intEndDays = intEndDays + 1
       End If
       varDateCnt = DateAdd("d", 1, varDateCnt)
    Loop
    WorkDays = varWholeWeeks * 5 + intEndDays

ExitHere:
   Exit Function

HandleErrors:
   Select Case Err.Number
      Case Else
         MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
         Resume ExitHere
   End Select
End Function
'------------------------------------------------------------------
I hope it helps!
 
Upvote 0

Forum statistics

Threads
1,221,826
Messages
6,162,192
Members
451,752
Latest member
majbizzaki

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