Here is a function that does exactly that. To exclude week ends is easy,
but
to capture holidays, you need a holiday table that has a record for each
date
that is not a work day. This code includes such a table. If you have a
holiday table, change the code to use your names; if not, create a table.
Mine has only two fields - a date and a description.
'---------------------------------------------------------------------------------------
' Procedure : CalcWorkDays
' DateTime : 5/8/2006 16:34
' Author : Dave Hargis
' Purpose : Counts the number of days between two dates excluding
Saturdays,
' : Sundays, and any days in the Holidays table
'---------------------------------------------------------------------------------------
'
Function CalcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer
On Error GoTo CalcWorkDays_Error
'Calculates the number of days between the dates
'Add one so all days are included
CalcWorkDays = DateDiff("d", dtmStart, dtmEnd) - _
(DateDiff("ww", dtmStart, dtmEnd, 7) + _
DateDiff("ww", dtmStart, dtmEnd, 1)) + 1
'Subtract the Holidays
CalcWorkDays = CalcWorkDays - DCount("*", "dbo_holiday_list",
"[holidate] between #" _
& dtmStart & "# And #" & dtmEnd & "#")
CalcWorkDays_Exit:
On Error Resume Next
Exit Function
CalcWorkDays_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure CalcWorkDays of Module modDateFunctions"
GoTo CalcWorkDays_Exit
End Function
--
Dave Hargis, Microsoft Access MVP
vbcraft said:
Hi,
Here is what i am trying to do:
I want to take todays date and return the appropriate day which is 50
days
from today. I want to use business days only.
ie. Now() - 50
but only using days monday to friday
Does anyone know how to do this