Add working days to a date

dark11984

Registered User.
Local time
Tomorrow, 08:42
Joined
Mar 3, 2008
Messages
129
Hi,
I am trying to find a code that will result in the working date 2 days from the current date excluding weekends and holidays which are listed in a table called tblholidays.

I'm pretty sure the code below is what i am after but i am just not sure how to incorporate the holidays table into it?

Code:
Public Function dhAddWorkDaysA(lngDays As Long, _
Optional dtmDate As Date = 0, _
Optional adtmDates As Variant) As Date
    ' Add the specified number of work days to the
    ' specified date.
    
    ' Modified from code 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 add to 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 from the start, taking
    '       into account weekends and holidays.
    ' Example:
    '   dhAddWorkDaysA(10, #2/9/2000#, Array(#2/16/2000#, #2/17/2000#))
    '   returns #2/25/2000#, which is the date 10 work days
    '   after 2/9/2000, if you treat 2/16 and 2/17 as holidays
    '   (just made-up holidays, for example purposes only).
    
    ' 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 = dhNextWorkdayA(dtmTemp, adtmDates)
    Next lngCount
    dhAddWorkDaysA = dtmTemp
End Function

Thanks,

DARK11984
 
I think you are missing part of the code required.
I see another function dhNextWorkdayA in your procedure , but no reference to this other function.

I don't have access to my copy of the ADH2000 handbook from where I am currently.

As for holidays, the comments in the procedure say
' adtmDates (Optional):
' Array containing holiday dates. Can also be a single
' date value, if that's what you want.


There is a function to do similar calculation at
http://www.utteraccess.com/forum/lofiversion/index.php/t1959936.html
 
Last edited:

Users who are viewing this thread

Back
Top Bottom