0
votes

I want to calculate two dates difference in Lotusscript. e.g. (10/18/2011 - 08/18/2011) = 71 days

4
Lotus script is a variant of BASIC, so the javascript tag is inappropriate.RobG

4 Answers

5
votes

From the Lotus Designer help:

TimeDifference method, Finds the difference in seconds between one date-time and another.

notesDateTime.TimeDifference( notesDateTime )
1
votes
d1 = DateNumber(2011,10,18)
d2 = DateNumber(2011,8,18)

d1 = d1 - d2
MessageBox d1
1
votes

Here is a snippet you can put in a button to see how it works:

Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace   
Dim uidoc As NotesUIDocument        
Dim doc As NotesDocument            
Dim startDT As New NotesDateTime("")
Dim endDT As New NotesDateTime("")
Dim diff As Long

Set uidoc = workspace.CurrentDocument   
Set doc = uidoc.Document        

Set startDT = doc.getFirstItem("StartDate").dateTimeValue
Call startDT.SetAnyTime 
Set endDT = doc.GetFirstItem("ReturnDate").dateTimeValue
Call endDT.SetAnyTime   
diff = startDT.TimeDifference(endDT)    
Msgbox Cstr(diff)   
End Sub

Here is a table I keep to help me get my brain around the numbers:

<table>
  <tr>
    <th>startDT</th>
    <th>endDT</th>
    <th>Result</th>
  </tr>
  <tr>
    <td>June</td>
    <td>March</td>
    <td>Positive</td>
  </tr>
  <tr>
    <td>June</td>
    <td>October</td>
    <td>Negative</td>
  </tr>
</table>

If March is 3, you must add (i.e. Postive) to get to June, which is 6. If June is still 6, to get there from October, you must subtract (i.e. Negative).

0
votes

It very much depends on what you're storing the date in. Date Programming is a big pain in Lotusscript.

If you're using NotesDateTime objects, then Jasper's solution is the best, although I get confused as to what is substracted from what.

A simple way is just to convert the date-time item values to singles, and substract. The part before the decimal point are days, the part after are the hours etc...