Results 1 to 4 of 4

Thread: Date Function

  1. #1
    Join Date
    May 2003
    Posts
    25

    Question Date Function

    I need to code a Date Function that calculates work days only but it's not working. Can someone help?

    Here's the function:

    Public Function DifferenceInDates(sStartDate, sEndDate)
    Dim iDays
    Dim iWorkDays
    Dim sDay
    Dim i
    DifferenceInDates() As Integer

    iDays = DateDiff("d", sStartDate, sEndDate)

    iWorkDays = 0

    For i = 0 To iDays
    'First day of the week is Sunday
    sDay = Weekday(DateAdd("d", i, sStartDate))
    If sDay <> 1 And sDay <> 7 Then
    iWorkDays = iWorkDays + 1
    End If
    Next
    DifferenceInDates = iWorkDays
    -------------------------------------

    And here is the portion of the code I'm using it in:

    iWorkDays = -(DateDiff("d", date, DateTrigger))
    If iWorkDays < 4 Then DoCmd.SendObject acSendNoObject, , , vString, vString2, , "Signature Requested", "Drawing# " & DocTrigger & " (for " & CycleTrigger & ") submitted for the " & ProgramTrigger & " program has been on the sign-off table since " & DateTrigger & ". Please sign.", False
    End If

    If iWorkDays > 3 And iWorkDays < 6 Then DoCmd.SendObject acSendNoObject, , , vString & vString2, vString3, , "Important Information!", "Drawing# " & DocTrigger & " (for " & CycleTrigger & ") submitted for the " & ProgramTrigger & " program has been on the sign-off table since " & DateTrigger & ".", False
    End If

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    works fine for me.

    Public Function GetNumberOfWorkDays(sStartDate, sEndDate)
    Dim iDays
    Dim iWorkDays
    Dim sDay
    Dim i

    iDays = DateDiff("d", sStartDate, sEndDate)

    iWorkDays = 0

    For i = 0 To iDays
    'First day of the week is sunday
    sDay = Weekday(DateAdd("d", i, sStartDate))
    If sDay <> 1 And sDay <> 7 Then
    iWorkDays = iWorkDays + 1
    End If
    Next
    GetNumberOfWorkDays = iWorkDays
    End Function

    Private Sub Command0_Click()
    MsgBox GetNumberOfWorkDays("8/1/2003", "8/30/2003")


    End Sub

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    put startdate as origination date and end date as todays date
    MsgBox GetNumberOfWorkDays("8/1/2003", Now())


    Please do not post the same thread in two different database journal forums.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •