OpenNTF.org - Calculate The Number Of Weekda
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Calculate The Number Of Weekdays Between Two Date Fields (Excluding Weekends And Holidays) Through 
Rating:
Not Rated Yet 
Contributor:
Andrew Jones 
Category:
Lotusscript 
Type:
 
Last Modified:
17 Jun 2002 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description





The Code on the trigger
'declarations
Dim Date1 As notesdatetime
Dim Date2 As notesdatetime
Set Date1 = New notesdatetime(doc.FirstDate(0))
Set Date2 =New notesdatetime(doc.SecondDate(0))
Differ# = Date2.TimeDifference(Date1)
If Differ# > 0 Then
Days% = Differ# / 86400
Days% = CycleTimeDate1,Date2,days%)
doc.CT1 = Days% 'where CT1 is a Field to capture the difference and
store it in a form
Else
doc.CT1 = 0
End If

In a Library create a function "Cycletime"

Function CycleTime(Date1 As notesdatetime, Date2 As notesdatetime,days As
Integer)
Dim hdoc As notesdocument
Dim view As notesview
Dim Y As Integer,x As Integer

Set ses = New notessession
Set Cdb = ses.currentdatabase
Set view = Cdb.getview("holiday")
x% = days%
Y% = 0
Do Until Y% = x%
Y% = Y%+ 1
Call Date1.AdjustDay(1)
Wday1$ = Cstr(Date1.LocalTime)
Set hdoc = view.getdocumentbykey(Wday1$ )
If Not hdoc Is Nothing Or Weekday(Date1.DateOnly)=1 Or
Weekday(Date1.DateOnly)= 7 Then
days% = days% - 1
CycleTime = days%
Else
CycleTime = days%
End If
Loop
End Function


Usage / Example
 Comments
Posted by Alan Bell on 04/17/2003 04:16:18 AMa quicker way to do it . . .
use the full text search engine to return the count of holiday documents between your start and end dates. Works very fast but you need to pass the dates in a search query string so have to worry about the potential difference in date format between client and server dd/mm/yyy vs mm/dd/yyyy.
 Add your comment!