Filtering Items Using a Date-time Comparison
Outlook Developer Reference |
Filtering Recurring Items in the Calendar Folder
To filter a collection of appointment items that include recurring appointments, you must use the Items collection. Use the Items.IncludeRecurrences property to specify that Items.Find or Items.Restrict should include recurring appointments. The Table object returns only one row representing the recurrent appointment item, instead of a row for each occurrence of the appointment.
Date-time Format of Comparison Strings
Date-time values are recognized according to the time format, short date format, and long date format settings in the Regional and Language Options applet in the Windows Control Panel.
Although dates and times are typically stored with a date format, filters using the Jet and DAV Searching and Locating (DASL) syntax require that the date-time value to be converted to a string representation. In Jet syntax, the date-time comparison string should be enclosed in either double quotes or single quotes. In DASL syntax, the date-time comparison string should be enclosed in single quotes.
To make sure that the date-time comparison string is formatted as Microsoft Office Outlook expects, use the Visual Basic for Applications Format function (or its equivalent in your programming language). The following example creates a Jet filter to find all contacts that have been modified before June 12, 2005 at 3:30 P.M local time.
|
Time Zones Used in Comparison
When an explicit built-in property is referenced in a Jet query with its explict string name, the comparison evaluates the property value and the date-time comparison string as local time values.
When a property is referenced in a DASL query by namespace, the comparison evaluates the property value and the date-time comparison string as Coordinated Universal Time (UTC) values. For example, the following DASL query finds all contacts that have been modified before June 12, 2005 at 3:30 pm, UTC.
|
Conversion to UTC for DASL Queries
Since DASL queries always perform date-time comparisons in UTC, if you use a date literal in a comparison string, you must use its UTC value for the comparison. You can use the Row.LocalTimeToUTC helper function or Outlook date-time macros to facilitate the conversion.
LocalTimeToUTC
One way to facilitate local time to UTC conversion is to use the helper function, LocalTimeToUTC, of the Row object. The following line of code uses this helper function to convert the value of the LastModificationTime property (which is a default column in all Table objects):
|
Outlook Date-time Macros
The date macros listed below return filter strings that compare the value of a given date-time property with a specified date in UTC; SchemaName is any valid date-time property referenced by namespace.
Note |
---|
Outlook date-time macros can be used only in DASL queries. |
Macro | Syntax | Description |
today | %today("SchemaName")% | Restricts for items with SchemaName property value equal to today |
tomorrow | %tomorrow("SchemaName")% | Restricts for items with SchemaName property value equal to tomorrow |
yesterday | %yesterday("SchemaName")% | Restricts for items with SchemaName property value equal to yesterday |
next7days | %next7days("SchemaName")% | Restricts for items with SchemaName property value equal to next 7 days |
last7days | %last7days("SchemaName")% | Restricts for items with SchemaName property value equal to last 7 days |
nextweek | %nextweek("SchemaName")% | Restricts for items with SchemaName property value equal to next week |
thisweek | %thisweek("SchemaName")% | Restricts for items with SchemaName property value equal to this week |
lastweek | %lastweek("SchemaName")% | Restricts for items with SchemaName property value equal to last week |
nextmonth | %nextmonth("SchemaName")% | Restricts for items with SchemaName property value equal to next month |
thismonth | %thismonth("SchemaName")% | Restricts for items with SchemaName property value equal to this month |
lastmonth | %lastmonth("SchemaName")% | Restricts for items with SchemaName property value equal to last month |
Example Showing Conversion to UTC
The following code example illustrates three filter strings that return all messages received today, and applies one of the filters to Items.Restrict and Application.AdvancedSearch. It first uses PropertyAccessor.LocalTimeToUTC to convert today’s date to UTC date strings. The first filter uses the Outlook macro, today, to obtain a filter string that compares the ReceivedTime property with today's date in UTC. The second and third macros reference the ReceivedTime property by two different namespaces. The code example finally applies the third filter to items in the Inbox twice, first using Items.Restrict and then using Application.AdvancedSearch. It prints the number of items in the Inbox, and the number of items returned from each application of the filter.
|
See Also