Article ID: 932955 - Last Review: January 15, 2008 - Revision: 5.2 How to handle dates and times that include DST
On This PageINTRODUCTIONDevelopers who write applications that handle dates and times may use one or more technologies that perform date manipulation and time manipulation. In particular, certain base operating system APIs, the C runtime (CRT), and the Microsoft .NET Framework may convert or otherwise manipulate dates and times. This article describes some of the general concepts that are involved in handling dates and times. In addition, this article describes the effect of the daylight saving time (DST) 2007 changes on certain products and technologies. MORE INFORMATIONTime storage and manipulationTimestamps are values that specify a date and time combination. Applications that must handle timestamps typically store those timestamps in Universal Coordinated Time (UTC). The advantage of UTC is that UTC is universal. UTC is not subject to local time zones or to DST. However, UTC is neither user-friendly nor relevant to most users. Although UTC is the obvious choice for storage, it is not a good choice for display. Therefore, most applications convert UTC time to local time before they display the timestamp to the user. For example, Windows Explorer applies the time zone and the DST setting to the UTC timestamp before it displays dates and times for files in a Windows NT File System (NTFS) directory.Conversion from UTC time to local time can be thought of as applying two offsets. The first is the time zone offset, and the second is the DST offset. Therefore, local time is effectively UTC time plus a time zone offset, plus any applicable DST offset. The time zone offset is fairly straightforward. The computer is configured for a particular time zone, and that time zone has an offset from UTC. To determine whether a DST offset should be applied is much more complex. This activity relies on many rules that are complex and dynamic. Those complex DST rules have recently changed with DST 2007. Starting in 2007, the United States has adopted new start dates and new end dates for DST. In addition, it is common for other countries and governments to routinely change the start dates and the end dates for DST in time zones that are under their control. The following section describes the effects of the DST 2007 change on developer-related products. For more information about DST 2007, visit the following Microsoft Web site: http://support.microsoft.com/gp/cp_dst
(http://support.microsoft.com/gp/cp_dst)
DST 2007 effects on developer-related technologiesWindowsOn Windows Update and on Microsoft Update, updates are available that enable Windows to correctly apply the changes for DST 2007 and for the following years. After these updates are applied, Windows correctly calculates the current offsets from UTC time to local time as the computer passes through DST. The offsets include the offsets for the base APIs and for the networking time-related APIs.For more information, click the following article number to view the article in the Microsoft Knowledge Base: 942763
(http://support.microsoft.com/kb/942763/
)
December 2007 cumulative time zone update for Microsoft Windows operating systems
C runtime (CRT)The CRT also performs date translations and time translations. Therefore, the CRT must also be updated to include the new rules for DST 2007. The CRT performs its own time handling only when the TZ environment variable is set or when an underlying operating system API time call fails. Updates are available for the CRTs that are included with each version of Microsoft Visual Studio and also for the CRTs that are included with Windows. These updates enable the CRT to continue to correctly handle DST conversions in United States time zones.The .NET FrameworkThe .NET Framework relies on the underlying operating system calls. Therefore, the behavior of the .NET Framework reflects the state of the underlying operating system. No separate update is required.Visual Studio .NET Integrated Development Environments (IDEs)The Visual Studio .NET IDEs include versions 2002, 2003, and 2005 of Microsoft Visual C++, Microsoft Visual C#, and Microsoft Visual Basic. These products are affected only because they include the CRT. No IDE-specific update is required.Visual Studio 2005 Team Foundation ServerVisual Studio 2005 Team Foundation Server relies on the underlying operating system for date and time conversions. Therefore, Visual Studio 2005 Team Foundation Server exhibits the same behavior as the operating system. Visual Studio 2005 Team Foundation Server also relies on Microsoft SQL Server, SQL Server Reporting Services, and Windows SharePoint Services. Computers should be updated with the relevant updates for the operating system, for SQL Server, and for Windows SharePoint Services. All relevant updates should be applied on all affected computers at the same time. No separate Visual Studio 2005 Team Foundation Server update is required.Visual Studio 2005 Team SystemVisual Studio 2005 Team System is affected through the operating system, through Visual Studio 2005 Team Foundation Server, and through the CRT. No separate Visual Studio 2005 Team System update is required.Visual SourceSafeFor more information about Visual SourceSafe DST issues in 2007, click the following article number to view the article in the Microsoft Knowledge Base:931804
(http://support.microsoft.com/kb/931804/
)
Visual SourceSafe daylight saving time issues in 2007
Visual Basic 6.0 runtimeThe Visual Basic 6.0 runtime is not affected.Visual C++ 6.0Visual C++ 6.0 is no longer supported.For more information, visit the following Microsoft Web site: http://support.microsoft.com/lifecycle/
(http://support.microsoft.com/lifecycle/)
Windows Software Development Kit (SDK) for Windows VistaThis SDK includes a version of the CRT that is affected by the DST 2007 changes. As part of the installation of this SDK, you can install the Visual Studio 2005 CRT on computers that do not already have that version of the CRT installed. If a newer version of the CRT is already installed, the SDK installation does not overwrite that newer version. When the SDK is uninstalled, the latest version of CRT is left on the computer. You may either install the Visual Studio 2005 CRT update before or after you install the SDK.The Windows SDK for Windows Vista also installs a set of merge modules (.msm files) for the Visual Studio 2005 CRT for redistribution of the CRT as part of custom C++ applications. An application that deploys the redistributable CRT to the installation folder of the application must deploy the updated CRT from the Visual Studio 2005 CRT update instead of the CRT .msm files from the Windows SDK for Windows Vista. An application that deploys the redistributable Visual Studio 2005 CRT update to the Windows installation folder must apply the Visual Studio 2005 CRT redistributable update to those computers. Platform SDK for Microsoft Windows Server 2003 R2This SDK includes a version of the CRT that is affected by the DST 2007 changes. Customers must follow the release notes for this SDK and use the Visual Studio 2005 CRT updates if they are necessary.The .NET Framework 2.0 SDKThis SDK includes a version of the CRT that is affected by the DST 2007 changes. As part of the installation of this SDK, you can install the Visual Studio 2005 CRT on computers that do not already have that version of the CRT installed. If a newer version of the CRT is already installed, the SDK installation does not overwrite that newer version. When the SDK is uninstalled, the latest version of CRT is left on the computer. You may either install the Visual Studio 2005 CRT update before or after you install the SDK.Local time conversion in WindowsApplications typically convert UTC times to local times before they display time information and date information to the user. Windows provides several APIs for applications to use for timestamp manipulation.
To see an example of this behavior in Windows Explorer, follow these steps on a computer that resides in a time zone that uses DST. Be aware that these steps require that you change the system clock. Therefore, you must exit any applications, such as calendar applications, that might react to these time changes before you follow these steps.
For more information, see this blog: http://blogs.msdn.com/oldnewthing/archive/2003/10/24/55413.aspx
(http://blogs.msdn.com/oldnewthing/archive/2003/10/24/55413.aspx)
The SystemTimeToTzSpecificLocalTime() method and the TzSpecificTimeToSystemTime() method convert between UTC time and the local time by using the provided TIME_ZONE_INFORMATION structure. If no time zone information is provided, these functions use the current time zone rules and the DST rules to determine whether a DST offset must be applied to the timestamp. This is functionally equivalent to calling the GetTimeZoneInformation() method to obtain the TIME_ZONE_INFORMATION structure that is currently in effect. The TIME_ZONE_INFORMATION structure includes the start date and the stop date for DST. Therefore, when the TIME_ZONE_INFORMATION structure uses the current time zone information, the TIME_ZONE_INFORMATION structure may introduce a historical inaccuracy. This behavior may occur if the current time zone information and the DST information do not reflect the timestamp that is being converted. This behavior is affected by DST 2007 only because the rules that govern the dates when DST starts and stops have been changed. To obtain historically accurate conversions from these functions, an application must provide a historically accurate TIME_ZONE_INFORMATION structure when the application calls these functions. Dynamic time zones in WindowsWindows Vista introduces dynamic DST time zones. Dynamic DST provides support for time zones whose boundaries for DST change from year to year. These rules are stored in the registry. Applications can query the rules by using the GetDynamicTimeZoneInformation() function.Dynamic time zones enable easier updating of computers, especially for locales where the yearly DST boundaries are known in advance. For more information about the DYNAMIC_TIME_ZONE_INFORMATION structure in the Windows SDK for Vista, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms724253.aspx
(http://msdn2.microsoft.com/en-us/library/ms724253.aspx)
Local time conversion in the C runtime (CRT)The CRT basically has three modes in which it can translate timestamps:
Note This conversion follows rules specific to the United States. Before you apply the DST 2007 update, the CRT correctly handles current timestamps in United States time zones. After you apply the DST 2007 update, the CRT also handles both past and future United States dates. Updates for the CRT are listed in the “References” section. Local time conversion in the .NET FrameworkThe .NET Framework contains classes that store and convert timestamps. These classes include the DateTime class, the TimeZone class, the TimeSpan class, and the DateTimeKind class. As previously noted, these classes depend primarily on the underlying platform implementation. These classes exhibit the same behavior as the underlying operating system APIs.One interesting behavior exhibited by the .NET Framework date classes and time classes relates to the functions that offset the timestamp by a requested amount. For example, consider the AddHours() function, the AddMinutes() function, and the AddSeconds() function in the DateTime class. These functions, and similarly named functions, merely increment the timestamp by the requested amount without regard for DST settings. This behavior might be considered simple arithmetic on the underlying UTC timestamp. However, this behavior could lead to unexpected outcomes when the addition causes the timestamp to pass into or out of DST. This behavior is unrelated to DST 2007 changes. RecommendationsThe following recommendations can help developers minimize the effect of DST 2007 and improve general date and time handling.
REFERENCESFor more information about the DST 2007 Microsoft portal, visit the following Microsoft Web site:http://support.microsoft.com/gp/cp_dst
(http://support.microsoft.com/gp/cp_dst)
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
942763
(http://support.microsoft.com/kb/942763/
)
December 2007 cumulative time zone update for Microsoft Windows operating systems
931975
(http://support.microsoft.com/kb/931975/
)
How to prepare SQL Server 2005 and SQL Server 2000 for changes to daylight saving time in 2007
931804
(http://support.microsoft.com/kb/931804/
)
Visual SourceSafe daylight saving time issues in 2007
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:http://msdn2.microsoft.com/en-us/library/ms724277.aspx
(http://msdn2.microsoft.com/en-us/library/ms724277.aspx)
To obtain DST 2007 updates for the C runtime (CRT), click the following article numbers to view the articles in the Microsoft Knowledge Base:http://msdn2.microsoft.com/en-us/library/ms724490.aspx (http://msdn2.microsoft.com/en-us/library/ms724490.aspx) http://msdn2.microsoft.com/en-us/library/ms725473.aspx (http://msdn2.microsoft.com/en-us/library/ms725473.aspx) 932305
(http://support.microsoft.com/kb/932305/
)
FIX: Visual C++ .NET 2002 C runtime daylight saving time 2007 update for the TZ environment variable problem
932304
(http://support.microsoft.com/kb/932304/
)
FIX: Visual C++ .NET 2002 Service Pack 1 C runtime daylight saving time 2007 update for the TZ environment variable problem
932299
(http://support.microsoft.com/kb/932299/
)
FIX: Visual C++ .NET 2003 C runtime daylight saving time 2007 update for the TZ environment variable problem
932298
(http://support.microsoft.com/kb/932298/
)
FIX: Visual C++ .NET 2003 Service Pack 1 C runtime daylight saving time 2007 update for the TZ environment variable problem
932392
(http://support.microsoft.com/kb/932392/
)
FIX: Visual C++ .NET 2005 C runtime daylight saving time 2007 update for the TZ environment variable
932391
(http://support.microsoft.com/kb/932391/
)
FIX: Visual C++ .NET 2005 Service Pack 1 C runtime daylight saving time 2007 update for the TZ environment variable
932590
(http://support.microsoft.com/kb/932590/
)
FIX: Windows-based applications that use the TZ environment variable may not work as expected because of changes to DST
APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
