Calculate Workdays

D

Dirk Goldgar

Jim McC said:
How can I manipulate the public function found at
http://www.mvps.org/access/datetime/date0012.htm

to subtract 2 days from the given date?

Untested, but:

'----- start of code -----
Public Function SubtractWorkDays( _
lngDays As Long, _
Optional dtmDate As Date = 0, _
Optional adtmDates As Variant) _
As Date

' Subtract the specified number of work days to the
' specified date.

' Modified By Dirk Goldgar from code published in
' "Visual Basic Language Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 2000; Sybex, Inc. All rights reserved.

' In:
' lngDays:
' Number of work days to subtract from the start date.
' dtmDate:
' date on which to start looking.
' Use the current date, if none was specified.
' adtmDates (Optional):
' Array containing holiday dates. Can also be a single
' date value, if that's what you want.
' Out:
' Return Value:
' The date of the working day lngDays before the start,
' taking into account weekends and holidays.

' Did the caller pass in a date? If not, use
' the current date.
Dim lngCount As Long
Dim dtmTemp As Date

If dtmDate = 0 Then
dtmDate = Date
End If

dtmTemp = dtmDate
For lngCount = 1 To lngDays
dtmTemp = dhPreviousWorkdayA(dtmTemp, adtmDates)
Next lngCount
SubtractWorkDays = dtmTemp

End Function
'----- end of code -----
 
J

Jim McC

That's it. Thank you

Dirk Goldgar said:
Untested, but:

'----- start of code -----
Public Function SubtractWorkDays( _
lngDays As Long, _
Optional dtmDate As Date = 0, _
Optional adtmDates As Variant) _
As Date

' Subtract the specified number of work days to the
' specified date.

' Modified By Dirk Goldgar from code published in
' "Visual Basic Language Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 2000; Sybex, Inc. All rights reserved.

' In:
' lngDays:
' Number of work days to subtract from the start date.
' dtmDate:
' date on which to start looking.
' Use the current date, if none was specified.
' adtmDates (Optional):
' Array containing holiday dates. Can also be a single
' date value, if that's what you want.
' Out:
' Return Value:
' The date of the working day lngDays before the start,
' taking into account weekends and holidays.

' Did the caller pass in a date? If not, use
' the current date.
Dim lngCount As Long
Dim dtmTemp As Date

If dtmDate = 0 Then
dtmDate = Date
End If

dtmTemp = dtmDate
For lngCount = 1 To lngDays
dtmTemp = dhPreviousWorkdayA(dtmTemp, adtmDates)
Next lngCount
SubtractWorkDays = dtmTemp

End Function
'----- end of code -----


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top