Results 1 to 2 of 2
  1. #1
    oldteddybear is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    4

    Date Problem


    I have two feilds DateStart and DateEnd.
    I have a query based on these [DateEnd]-[DateStart] which gives the total number of days between but I only want the number of working days (ie. Monday to Friday Inclusive) within the date ranges. I do not need to worry about other holidays.

    Note: Within the query there is a field [FinDate] that converts Null values in the DateEnd to todays date. Is there an easy solution to this problem? I am still learning about access so complicated solutions are not my strong point.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's a function for a standard module:
    Code:
    Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
    '-- Return the number of WorkingDays between StartDate and EndDate
       On Error GoTo err_workingDays
       Dim intCount As Integer
       If IsDate(StartDate) And IsDate(EndDate) Then
          If EndDate >= StartDate Then
             intCount = 0
             Do While StartDate < EndDate
                StartDate = StartDate + 1
                If Weekday(StartDate, vbMonday) <= 5 Then
                   '-- Use the following code if you have a "Holiday" table
                   '         If Weekday(StartDate, vbMonday) <= 5 And _
                             IsNull(DLookup("[Holiday]", "tblHolidays", _
                             "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
                   intCount = intCount + 1
                End If
             Loop
             WorkingDays = intCount
          Else
             WorkingDays = -1  '-- To show an error
          End If
       Else
          WorkingDays = -1  '-- To show an error
       End If
    exit_workingDays:
       Exit Function
    err_workingDays:
       MsgBox "Error No:    " & Err.Number & vbCr & _
              "Description: " & Err.Description
       Resume exit_workingDays
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-31-2009, 06:56 AM
  2. Problem with date field...
    By Rameez in forum Access
    Replies: 9
    Last Post: 06-23-2009, 10:29 AM
  3. problem in splitting Date and time fields
    By swaroop1012 in forum Queries
    Replies: 1
    Last Post: 11-22-2008, 11:29 AM
  4. Access Date/Time....I need a "generic" date.
    By beastmaster in forum Access
    Replies: 2
    Last Post: 12-29-2005, 12:55 PM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums