Adding working days

  • Thread starter Thread starter Alou
  • Start date Start date
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.
 
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.
 
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
 
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
 
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)
 
Back
Top