Adding working days

A

Alou

I'm creating codes for a field (in the form) to return 10 working days from
the initial date. Initial date is given and I want to get the date, 10
working days from the initial date.
 
P

pietlinden

I'm creating codes for a field (in the form) to return 10 working days from
the initial date.  Initial date is given and I want to get the date, 10
working days from the initial date.


see DateAdd in the help.
 
J

Jim Burke in Novi

Something like this should work:

Public Function DatePlus10WorkingDays(byVal firstDate as date) as date

dateCount = 0
workingDateCount = 0

while workingDateCount < 10
dateCount = dateCount + 1
if IsWorkingDate(firstDate + dateCount) then
workingDateCount = workingDateCount + 1
end if
wend

DatePlus10WorkingDays = firstDate + dateCount
exit Function

End Function

Public Function IsWorkingDate(byVal testDate as Date) as Boolean

if Weekday(testDate) > 1 and Weekday(testDate) < 7 then

' If you need logic for Holidays you'd include it here. Maybe have a table
of dates
' that are holidays and do a DLookup on that table with the passed date to
see
' if it's in the table. If so, it's not a working date, else it is.

IsWorkingDate = True
else
IsWorkingDate = False
End If

End Function
 
A

Alou

Thank you, Jim. I will try it and let you know.

Jim Burke in Novi said:
Something like this should work:

Public Function DatePlus10WorkingDays(byVal firstDate as date) as date

dateCount = 0
workingDateCount = 0

while workingDateCount < 10
dateCount = dateCount + 1
if IsWorkingDate(firstDate + dateCount) then
workingDateCount = workingDateCount + 1
end if
wend

DatePlus10WorkingDays = firstDate + dateCount
exit Function

End Function

Public Function IsWorkingDate(byVal testDate as Date) as Boolean

if Weekday(testDate) > 1 and Weekday(testDate) < 7 then

' If you need logic for Holidays you'd include it here. Maybe have a table
of dates
' that are holidays and do a DLookup on that table with the passed date to
see
' if it's in the table. If so, it's not a working date, else it is.

IsWorkingDate = True
else
IsWorkingDate = False
End If

End Function
 
A

aushknotes

Absolutely agreed. Why not use DateAdd sampled as follow:

Dim datDatePlus10 As Date
Dim datInitDate As Date

datInitDate = #10/10/2008#
datDatePlus10 = DateAdd("d", 10, datInitDate)
 
R

raskew via AccessMonster.com

Hi -

Give this a try:

Function UpBusDays3(pstart As Date, _
pNum As Integer, _
Optional pAdd As Boolean = True) As Date
'*******************************************
'Purpose: Add or subtract business days
' from a date
'Coded by: raskew
'Inputs: 1) +) ? UpBusDays3(#2/17/06#, 3, True)
' 2) -) ? UpBusDays3(#2/22/06#, 3, False)
'Output: 1) +) 2/22/06
' 2) -) 2/17/06
'*******************************************

Dim DteHold As Date
Dim i As Integer
Dim n As Integer

DteHold = pstart
n = pNum
For i = 1 To n
If pAdd Then 'add days
DteHold = DteHold + IIf(WeekDay(DteHold) > 5, 9 - WeekDay(DteHold),
1)
Else 'subtract days
DteHold = DteHold - IIf(WeekDay(DteHold) < 3, Choose(WeekDay
(DteHold), 2, 3), 1)
End If
Next i
UpBusDays3 = DteHold

End Function

HTH - Bob
 
Top