Help with showing dates on a calendar(Script)

Hi Guys

I have a form
On the form are 2 Date/Time fields

From and To

Also I have field WorkDays which is number field and TotalDays which is Date?Time with allw multi values
I have a view course calendar

I would like to show on the calendar view all the days a course runs
If it runs 1 day then show one day if it is longer then indicate each day that it runs
I know this involves subtracting the From field from the To field, not sure how to do that in script, I have tried a couple of things and it is not working out

I need to calculate this at the time the document is created so maybe call this function at the quesry save or postrecalc?


Here is the code in the globals that I have been trying to get to work

Sub CalculateWorkDays(workdays As Double)
'*******************************************************************************************
' Purpose : This subroutine is to calculate no. of working days which will be
' taken for course.  It also fills the field TotalDaysf so that it can populate the
' calendar views properly.
'  
'      Added & Modified to work with Session form and Course Calendar view in DIPR
'    db from LTVS db
      
'*******************************************************************************************    
      
      Dim session As NotesSession
      Dim ws As NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim dateTime As NotesDateTime
      
      Dim CompareDate As Variant
      Dim TotalDays As Variant
      Dim nonworkdays As Double
      Dim FromIsLessThanTo As Variant    
      Dim i As Double
      
      Set session = New NotesSession
      Set ws = New NotesUIWorkspace
      Set db = session.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.document
      workdays = 1
      nonworkdays = 0
      
      If doc.SessionDate(0) <> "" And doc.SessionDateEndDT(0) <> "" And (doc.SessionDate(0) <= doc.SessionDateEndDT(0)) Then
            FromIsLessThanTo = True            
            CompareDate = doc.SessionDate(0)
            TotalDays = 1
            
            While FromIsLessThanTo
                  If (CompareDate =>1 And CompareDate <= 5) Then
                        workdays  =workdays + 1          
                        
' Apr 2003 =====                        
'                        Set dateTime = New NotesDateTime (CompareDate + " 12:00:00 AM")  
                        Set dateTime = New NotesDateTime (CompareDate + " 8:00:00 AM")  
'==============                        
                        TotalDays = TotalDays + ";" + dateTime.LocalTime              
                  Else
                        nonworkdays = nonworkdays + 1
                  End If
                  CompareDate = CompareDate + 1
                  If CompareDate > doc.SessionDate(0) Then
                        FromIsLessThanTo = False
                  End If
            Wend
      End If
      doc.workdays = workdays
      doc.nonworkdays = nonworkdays          
      doc.TotalDays =  workdays
      
End Sub
imjameswAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
Would this be something for you?
http:Q_20920029.html "Calculating time interval between 2 date and time (excluding non-working days)"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imjameswAuthor Commented:
One thing I sshould add is that this is straight work week stuff, no calculations for weekends or holidays

0
qwaleteeCommented:
Didn't we go through code exactly like this about a year ago?

If we ignore the need to exclude weekends and holidays, it is real simple:
    allDaysInRange := @TextToTime(@Explode(@TextToTime(@Text(From) + " - "+ @Text(To))))

If you want to exclude weekends:
    textDaysInRange := @Explode(@TextToTime(@Text(From) + " - "+ @Text(To)));
    dateDaysInRange := @TextToTime(textDaysInRange);
    textDaysOfWeek := @Text(@Weekday(dateDaysInRange));
    marker := @Char(250);
    markWeekDays := @Replace(textDaysOfWeek; "2":"3":"4":"5":"6"; marker);
    textWorkDays := @Right(markWeekDays + textDaysInRange; marker);
    @TextToTime(textWorkDays);

If you want to exclude holidays, you need a list of holidays, and you can easily do a repace between the textWorkDays and the @TextToTime at the end.

If you need a count, just get @Elements of the result.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

imjameswAuthor Commented:
Yes we did, however I am trying to keep with the company standard and do it in script
Using what I have included below works ,I call it from a Postrecalc
Thanx abunch

James

Sub CalculateWorkDays(workdays As Double)
'*******************************************************************************************
' Purpose : This subroutine is to calculate no. of working days which will be
' taken for course.  It also fills the field TotalDaysf so that it can populate the
' calendar views properly.
'  
'      Added & Modified to work with Session form and Course Calendar view in DIPR
'    db from LTVS db
      
'*******************************************************************************************    
      
      Dim session As NotesSession
      Dim ws As NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim dateTime As NotesDateTime
      
      Dim CompareDate As Variant
      Dim TotalDays As Variant
      Dim nonworkdays As Double
      Dim FromIsLessThanTo As Variant    
      Dim i As Double
      
      Set session = New NotesSession
      Set ws = New NotesUIWorkspace
      Set db = session.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.document
      workdays = 0
      nonworkdays = 0
      
      If doc.SessionDate(0) <> "" And doc.SessionDateEndDT(0) <> "" And (doc.SessionDate(0) <= doc.SessionDateEndDT(0)) Then
            FromIsLessThanTo = True            
            CompareDate = doc.SessionDate(0)
            TotalDays = ""
            
            While FromIsLessThanTo
                  If (doc.SessionDate(0) < doc.SessionDateEndDT(0)) Then
                        workdays  = workdays + doc.SessionDateEndDT(0) - doc.SessionDate(0)
                  'TotalDays = TotalDays + ";" + CompareDate    
' Apr 2003 =====                        
'                        Set dateTime = New NotesDateTime (CompareDate + " 12:00:00 AM")  
                        Set dateTime = New NotesDateTime (CompareDate + " 8:00:00 AM")  
'==============                        
                        TotalDays = TotalDays + ";" + dateTime.LocalTime              
                  Else
                        nonworkdays = nonworkdays + 1
                  End If
                  CompareDate = CompareDate + 1
                  If CompareDate > doc.SessionDateEndDT(0) Then
                        FromIsLessThanTo = False
                  End If
            Wend
      End If
      doc.workdays = workdays
      doc.nonworkdays = nonworkdays          
      doc.TotalDays =  TotalDays
      
End Sub
0
Sjef BosmanGroupware ConsultantCommented:
So the Formula-stuff works? Then rebuild it in LS.

Otherwise, please define
- input
- process
- output
0
qwaleteeCommented:
I hate retarded company standards that are written by either people with outside egos or who do not understand hhow the product works.

There's one place where the first developer had done a lot of stuff over the years, and had some good, solid, 50%-formula, 50%-script solutions. Junior guy comes in, learns a little bit about Nootes by taking the cert classes, and is immediately coding everything in script and complaining thathe cant understand teh "crazy templates" designed by the senior guy.

Couple of months later, senor guy gets a job offer and walks.  The junior guy is the only guy, and whiel they are looking for a senior replacement, the junior guy sugests they create a standard forbidding formula on forms and in agents.  Ties the hands of the new senior guy with this.  Suddenly, everything takes twice as long, crashes more often, but, hey, a standard is a standard!
0
Sjef BosmanGroupware ConsultantCommented:
See the third statement in my EE-profile :)
0
imjameswAuthor Commented:
You are so right Qwalatee
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.