Microsoft KB Archive/208305

From BetaArchive Wiki

Article ID: 208305

Article Last Modified on 2/12/2007



APPLIES TO

  • Microsoft Office Outlook 2003
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Outlook 2000 Standard Edition



This article was previously published under Q208305

SYMPTOMS

When you use the SetColumns method to retrieve dates or times from tasks, the times may not accurately reflect what is stored in the task.

CAUSE

With the exception of tasks, all dates in Microsoft Outlook are stored in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT). However, tasks store dates in local time. The SetColumns method always converts the retrieved time into local time, therefore causing the times to be offset.

WORKAROUND

Use either of the following methods to work around this behavior.

Method 1: Do not use the SetColumns method

Do not use the SetColumns method to retrieve dates with tasks. In most cases, this adversely affects your solution's performance.

Method 2: Retrieve and use an OffSet

Note If you are using Microsoft Visual Basic Scripting Edition (VBScript), you cannot access the system registry and this workaround does not apply.

If you are using Microsoft Visual Basic or Microsoft Visual Basic for Applications, programmatically get the local time zone information from the computer running your application. This information is stored in the following location in the registry:

HKEY_Local_Machine\SYSTEM\CurrentControlSet\Control\TimeZoneInformation


The Bias value specifies the current bias, in minutes, for local time translation on the computer. The bias is the difference, in minutes, between local time and UTC. Use this value to correct the time retrieved using the SetColumns method.

MORE INFORMATION

The Date type is implemented as a floating-point value, measuring days from midnight, December 30, 1899. To interpret the time portion, take the absolute value of the fractional part of the number. Since the bias is measured in minutes however, you must divide the bias by the number of minutes in a day (1440) in order to perform the conversion. The formula is:

local time + (Bias / 1440 ) = UTC


For example, the Date value of a task to be started February 14, 1999 (UTC) should be 36205.0. However, if your application is run on a computer in New York, the Date value (local time) may be 36204.7916667 (February 13, 1999 7:00 P.M.). To perform the conversion, find the computer's bias from the registry, which is 0x0000012c (300 minutes). Using this in the formula, we have the following:

local time + (Bias / 1440 ) = UTC
36204.7916667 + (300/1440) = 36205.0
(February 13, 1999 7:00 PM + 5hrs) = February 14, 1999 0:00am


For more information about how to use Visual Basic to retrieve values from the registry, click the following article number to view the article in the Microsoft Knowledge Base:

145679 How to use the registry APIs to save and retrieve settings


Steps to reproduce the problem

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

  1. Create a new task in the default tasks folder.
  2. Set the Subject to New Task.
  3. Set the Start date to any date and time.
  4. Save the task.
  5. Enter the following automation code into Visual Basic or into Visual Basic for Applications.

    Private Sub Command1_Click()
       Dim OutApp As Outlook.Application
       Dim oNameSpace As Outlook.NameSpace
       Dim oFolder As Outlook.MAPIFolder
       Dim oItems As Outlook.Items
       Dim oTask As Outlook.TaskItem
    
       Set OutApp = New Outlook.Application
       Set oNameSpace = OutApp.GetNamespace("MAPI")
       Set oFolder = oNameSpace.GetDefaultFolder(olFolderTasks)
       Set oItems = oFolder.Items
    
       Set oTask = oItems("New Task")
       MsgBox CDbl(oTask.StartDate)
    
       oItems.SetColumns "StartDate"
       Set oTask2 = oItems("New Task")
       MsgBox CDbl(oTask2.StartDate)
    End Sub
                        
  6. Add a reference to the Microsoft Outlook 9.0 Object Library.
  7. Run the code.



Additional query words: OL2K OutSol OutSol2000 vbscript OutSol2002 OutSol2003

Keywords: kbbug kbnofix kbprogramming KB208305