Domino Code Fragment

Code Name*
How to Search for a Date Value When Using the GetDocumentByKey Method
Date*
05/14/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.143.17.25
Description*
Using the Format function, you can store the date in a mm/dd/yy format, which zero-fills the date and allows for
proper searching.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Problem:
How can you use the LotusScript GetDocumentByKey method of the NotesDatabase class to
search for a key which is based on a date?

Solution:
In order to properly search for a date value, you must use the LotusScript Format function. The
reason you must do this is because Notes views zero-fill date values, but LotusScript (by default)
does not zero-fill date values. For example, if you do not use the Format function and search for the
date: 01 02 97, the LotusScript code will store, and thus search for, 1 2 97. Using the Format
function, you can store the date in a mm/dd/yy format, which zero-fills the date and allows for
proper searching.

Dim docA as notesdocument
Dim docB as notesdocument
Dim view as notesview
Dim keys (1 to 1) of string
...
keys(1)= Format(docA.datefield(0),"mm/dd/yy")
set docB=view.getdocumentbykey(keys)