Domino Code Fragment

Code Name*
How to Compare Dates Using LotusScript
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.141.202.187
Description*
It seems as though comparing dates would be a straight-forward task; however, it is actually rather complicated. A quick, easy approach is to use simple comparison operators, but via this approach - the question remains of how you get the
dates from Notes into the back-end and then manipulate it once it is in the script. The following instructions and sample code,
however, demonstrate how you can do this:
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Note that a variant is defined to be an element of any size and any dimensions. By default, this is an array (or one element in this
case).
Files/Graphics attachments (if applicable): Code:

1. In a sample database, create a new form.


2. Create two date/time fields, named: time_today and time_yesterday


3. Create an action button (on the form).


4. Place the following code in the action button:


Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace 'dimensions the workspace
Dim uidoc As NotesUIDocument 'dimensions the front end uidoc
Dim doc As NotesDocument 'dimensions the back end doc


Dim Time_today As Variant 'dimensions a variant for today
Dim Time_yesterday As Variant 'dimensions a variant for yesterday


Set uidoc = workspace.CurrentDocument 'Assigns the front end doc to the current document
Set doc = uidoc.Document 'Re-assigns the front end to the back end


Time_today = doc.time_today 'extract the time for today
Time_yesterday = doc.time_yesterday 'extract the time for yesterday
If Time_today(0) > Time_yesterday(0) Then 'compare the first element in each variant
Print "cool" 'print out a result if this is correct
Else
Print "bad" 'print out a result if this is not correct
End If
End Sub


5. OPTIONAL: This step is not necessary, but it makes the example easier to run.
Put the following formulas in the default section of the code:
@Date(@today)
@Date(@Yesterday)


6. Test the button.