Tuesday, April 13, 2010

@Businessdays equivalent in Lotusscript

Function businessDays( NewDate As Variant, OldDate As Variant) As Double
        Dim DateCnt As Long
        Dim NoDays As Long
        Dim BeginDate As Long
        Dim EndDate As Long
        Dim DayOfWeek As Integer
' This function calculates the difference between two dates in whole days and
'    does not include the start date , weekends are also excluded
        On Error Goto errDateDiff
        BeginDate =OldDate
        EndDate = NewDate
        DateCnt = BeginDate
        NoDays = 0
        Do While (DateCnt <= EndDate)
                DayOfWeek = Weekday(DateCnt)
                If Not (DayOfWeek = 1 Or DayOfWeek = 7) Then
                        NoDays = NoDays + 1
                End If
                DateCnt = DateCnt + 1
        businessDays= NoDays
        Exit Function

        businessDays= -1
        Exit Function
End Function

No comments:

Post a Comment