business days

Hi all,

I am trying to account for business days when calculating an array of date3 which is an array of dates between date1 and date2.

I am aware of @businessday function and I am able to calculate the business days but I will need to incorporate this in my lotusscript. Basically, if a user has the excludeweekend field on form ticked I want to invoke a date calculation without the weekend, else calculate it normally which is the script that I currently have.

For example,

      'small portion of script

      date1= doc.startdate(0)
      date2= doc.enddate(0)
      
      interval= doc.Interval(0)
      
      date1= date1 + interval
            
      n= Cint((date2-date1)/interval)
      
      If n>=0 Then
            Redim dates(n) As Variant
            i= 0
            Do While date1<=date2
                  dates(i)= Cdat(date1)
                  i= i + 1
                  date1= date1 + interval
            Loop
            
            If doc.date3(0) = "" Then
                  doc.date3 = dates
                  
            End If
      End If

varvouraAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
Function MoveToNextBusinessDay(d As Variant) As Variant
    Dim d2 As Variant

    Select Case Weekday(d2)
    Case 1
        d2= d+1
    Case 7
        d2= d+2
    Case Else
        d2= d
    End Select
    MoveToNextBusinessDay= d2
End Function

Just a hunch: the testers won't be happy with the planning resulting from this code...
0
 
Sjef BosmanGroupware ConsultantCommented:
    'small portion of script

     date1= doc.startdate(0)
     date2= doc.enddate(0)
     
     interval= doc.Interval(0)
     
     date1= date1 + interval
         
     n= Cint((date2-date1)/interval)
     
     If n>=0 Then
          Redim dates(n) As Variant
          i= 0
          Do While date1<=date2
               dates(i)= MoveToNextBusinessDay(Cdat(date1))
               i= i + 1
               date1= date1 + interval
          Loop
         
          If doc.date3(0) = "" Then
               doc.date3 = dates
               
          End If
     End If

and define a function

Function MoveToNextBusinessDay(d As Variant)
...
...
    MoveToNextBusinessDay= d2
End Function
0
 
varvouraAuthor Commented:
Could move to MovetoNextBusinessday be something simple like the following?

Function MoveToNextBusinessDay (thisDate As Variant) As Integer

thisDateVar = Datevalue(Cdat(date1))

If (Weekday(thisDateVar) = 1) Or (Weekday(thisDateVar) = 7) Then
MoveToNextBusinessDay = False
Else
MoveToNextBusinessDay=True

End If
Exit Function

MoveToNextBusinessDay = False
End Function
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Sjef BosmanGroupware ConsultantCommented:
Naaah, it is simple, but it is supposed to return a date value. Why do difficult if it can be simple. It will return the same day if it's a weekday, the next day (when Sunday) or two days later (when the parameter d is a Saturday).
0
 
varvouraAuthor Commented:
OK, let's try again, I have to get this right.
Do we have to define a function, can't we for example do something similar to modifications below. I am sure it isn't correct, but tell me if it can be done and i can try to work around it.....

Dim session As New notessession
      Dim uiworkspace As New notesuiworkspace
      Dim db As notesdatabase
      Set db = session.currentdatabase
      Dim uidoc As notesuidocument
      Dim doc As notesdocument      
      Set uidoc = uiworkspace.CurrentDocument
      Set doc = uidoc.document
      
      
      Dim d1 As Variant
      Dim d2 As Variant
      
      Dim interval As Integer
      Dim dates() As Variant
      Dim i As Integer
      Dim n As Integer
      
      d1= doc.startdate(0)
      d2= doc.enddate(0)
      
      interval= doc.Interval(0)
      d1= d1 + interval
      n= Cint((d2-d1)/interval)
      
      If n>=0  & excludeweekend = "N" Then
            Redim dates(n) As Variant
            i= 0
            Do While d1<=d2
                   If (Weekday(d1) = 1) Or (Weekday(d) = 7) Then

                  dates(i)= Cdat(d1 + 1)
                                    i = i + 1
                  d1= d1 + interval
                   else
                            dates(i) = Cdat(d1)
                             i = i + 1
                      d1= d1 + interval
            Loop
            
            If doc.resultsdate(0) = "" Then
                  doc.resultsdate = dates
                  
            End If
      End If
      



0
 
varvouraAuthor Commented:

Just a hunch: the testers won't be happy with the planning resulting from this code...

Why exactly?
0
 
varvouraAuthor Commented:
sjef, I am posting this other code so you can check it out.
It is a function that I requested in regards to difference between two arrays, but i think you guys didn't understand exactly what I am trying to get at.
I'll post it in another question, could you pls take a quick look.

0
 
varvouraAuthor Commented:
Just a hunch: the testers won't be happy with the planning resulting from this code...

Do you mean because they'll perform less tests for the year because of the weekend exclusion?

0
 
Sjef BosmanGroupware ConsultantCommented:
And didn't you have a similar function in one of your earlier questions??

Yes, you could put everything in one module. But what's the point? Instead of a fine function that you can give a meaningful name you now have some meaningless code inside the first module. If that suits you, fine with me :)

WHy they won't be happy? They have to do, statistically speaking, three times more tests on Monday than on any other day!
0
 
varvouraAuthor Commented:
Re: happy testers

dah!!I am glad the reason wasn't technical. I have enough problems to deal with.

Thanks sjef, as always, your help in much appreciated.
0
All Courses

From novice to tech pro — start learning today.