Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

# Business Days

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
I have 2 fields that I need to use to calculate a Service Date.

The first field is "Created_Date" and the second is "Service_Level_days.

The Service level days is the number of business days a item needs to be "closed" in. I need to create a field that shows the following:

if the Created_date = 1/3/2017 and the Service_Level_days = 2 i need the Service_date to = 1/31/2017

Is there a way to accomplish this in a querey?

Thanks for any help or suggestions.

Paul
 
Hi,

Every company I have worked for, has a Business Calendar table, containing workdays, holidays, accounting weeks/months etc.

Join your table(s) to your Business Calendar using the appropriate criteria for your requirements.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thank you Skip, I will look into that.
 
Build yourself a table of non work days for your business. Do not include weekends. Make it for many years out. Apply your business rules.

Code:
tblHolidays
ID	dtmDate	        Type
1       1/1/2017        New Years
2       1/16/2017       MLK
3       1/20/2017       Innauguration
....
n       12/25/2030      XMas


Build a UDF and helper UDFs

Code:
Public Function GetServiceDate(CreatedDate As Variant, LevelDays As Variant) As Date
  Dim i As Integer
  Dim Bizdays As Integer
  
  If IsDate(CreatedDate) And Not IsNull(LevelDays) Then
    GetServiceDate = CreatedDate
    Do
      GetServiceDate = GetServiceDate + 1
      If Not IsHoliday(GetServiceDate) And Not IsWeekend(GetServiceDate) Then Bizdays = Bizdays + 1
    Loop Until Bizdays = LevelDays
  End If
End Function

Public Function IsHoliday(dtmDate As Date) As Boolean
  IsHoliday = (DCount("*", "tblHolidays", "dtmDate = #" & dtmDate & "#") > 0)
End Function

Public Function IsWeekend(dtmDate As Date) As Boolean
  IsWeekend = (Weekday(dtmDate) = vbSunday Or Weekday(dtmDate) = vbSaturday)
End Function

in a query
Code:
Select ...., GetServiceDate([Created_Date],[Service_Level_days]) AS Service_Date from sometable ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top