Working with Dates and Times
Dates and times are defined and set using the NotesDateTime class. After a value has been assigned to an object, the Format() command can be used to format the value, or a variety of methods (such as AdjustDay and AdjustMonth) can be used to modify the object value. You can also use various object properties to refine the values associated with the date and time.
How It Works
Declare a DateTime object variable and set its value. After it is set, use one of the NoteDateTime properties such as LocalTime, DateOnly, TimeOnly, or TimeZone to extract a particular value. To modify the date or time, use one of the methods to adjust the object value.
ImplementationExample 1
The first example retrieves only the time value associated with a NotesDateTime object (see Figure 13.7).
Dim dateStamp As NotesDateTime Set dateStamp = New NotesDateTime("08-17-2005 02:00:00 PM ET") Msgbox dateStamp.TimeOnly
Figure 13.7. Example of the TimeOnly property
ImplementationExample 2
This second example returns just the date associated with a DateTime object (see Figure 13.8).
Dim dateStamp As NotesDateTime Set dateStamp = New NotesDateTime("08-17-2005 02:00:00 PM ET") Msgbox dateStamp.DateOnly
Figure 13.8. Example of the DateOnly property
ImplementationExample 3
This third example illustrates the DateOnly property and how to retrieve the current date using the Today function. In this example, the current date is November 11, 2005.
Dim dateStamp As NotesDateTime Set dateStamp = New NotesDateTime("Today") Msgbox dateStamp.DateOnly
ImplementationExample 4
This fourth example illustrates how to use the AdjustDay method to change the date 10 days in the future (see Figure 13.9). Be sure the dateStamp object contains a valid date prior to using the AdjustDay (or any other) method.
Dim dateStamp As NotesDateTime Set dateStamp = New NotesDateTime("Today") Call dateStamp.AdjustDay(10) Msgbox "10 days in future: " & dateStamp.DateOnly
Figure 13.9. Example of the AdjustDay method
Note
You can adjust the date or time backward by passing a negative value to the method. For example, to adjust the date backward by 10 days, replace the AdjustDay value above with -10.