Microsoft Knowledge Base Email Alertz

KBAlertz.com: How the changes to DST in 2007 affect the .NET Framework and ASP.NET

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 2.0 Web Hosting with SQL 2005: Click Here!
Discount ASP.NET Hosting


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




How the changes to DST in 2007 affect the .NET Framework and ASP.NET

Article ID:933509
Last Review:December 3, 2007
Revision:1.3
On This Page

INTRODUCTION

This article describes how the changes to daylight saving time (DST) in 2007 affect developers who use the Microsoft .NET Framework.

These changes do not affect Microsoft Internet Information Services (IIS). However, these changes may affect some Web pages that are developed in Microsoft ASP.NET and that use the System.TimeZone namespace.

Back to the top

MORE INFORMATION

Starting in 2007, the start date and the end date for DST in the United States will change to comply with the U.S. Energy Policy Act of 2005. Therefore, DST in the United States starts three weeks earlier than it started in the past. Additionally, DST ends one week later than it ended in the past. DST now uses the following start date and the following end date:
•Daylight saving time starts at 2:00 A.M. on the second Sunday in March.
•Daylight saving time ends at 2:00 A.M. on the first Sunday in November.
For the .NET Framework, you may experience a problem that involves the System.TimeZone namespace and historical calculations. The nature of the problem depends on whether you have applied the DST hotfix that is described in Microsoft Knowledge Base article 928388 on a computer that is running the .NET Framework. If you have applied this hotfix on a computer that is running the .NET Framework, calculations are incorrect for the affected times in 2006 and in earlier years. If you have not applied this hotfix on the computer that is running the .NET Framework, calculations for the problem dates are incorrect for 2007 and for later years.

For example, the DST change affects March 28. If you apply the hotfix that is described in Microsoft Knowledge Base article 928388, the TimeZone.CurrentTimeZone.IsDaylightSavingTime function returns the correct value (true) for March 28, 2007. However, the TimeZone.CurrentTimeZone.IsDaylightSavingTime function also returns a value of true for March 28, 2006. This function should return a value of false for March 28, 2006.

Additionally, many developers use coordinated universal time (UTC) in calculations to avoid various DST issues. Programs that use UTC also receive incorrect values for the problem dates. For example, if you use the DateDiff method to determine the number of hours between 1:00 A.M. on March 12, 2006, and 5:00 A.M. on March 12, 2006, you receive a value of three hours instead of the correct value of four hours. According to the new DST rules, clocks move ahead one hour on the second Sunday of March.

Back to the top

Example scenario

The following example scenario assumes that the following conditions are true:
•The computer is running the .NET Framework.
•You have applied the hotfix that is described in the following Microsoft Knowledge Base article:
928388 (http://kbalertz.com/Feedback.aspx?kbNumber=928388/) 2007 time zone update for Microsoft Windows operating systems
The following code example returns a value of true:
Dim DateSet As New DateTime()
DateSet = Convert.ToDateTime("3/28/2006 1:00:00 PM")
Label1.Text = DateSet.IsDaylightSavingTime()
To resolve this problem, create a function that handles the mismatched dates for a particular year and another function that finds the specific key dates for the particular year. For example, the functions may resemble the functions in the following code example.
Function GetKeyDate(ByVal MyMonthDay As String, ByVal myYear As Integer) As Date
        
        Dim NextSun As Date
        NextSun = MyMonthDay & myYear

	'Find the next Sunday.
        While Not (NextSun.DayOfWeek = DayOfWeek.Sunday)
            NextSun = NextSun.AddDays(1)
        End While
        GetKeyDate = NextSun
    End Function

    Function FindCorrectDST(ByVal chkDate As DateTime) As Boolean
        Dim DST As Boolean
        DST = chkDate.IsDaylightSavingTime
        If chkDate.Year > 2006 Then
            Return DST
        End If
        Dim ds1, ds2, ds3, ds4 As Date
'Use the earliest possible key Sunday.
        ds1 = GetKeyDate("03/08", chkDate.Year)
        ds2 = GetKeyDate("04/01", chkDate.Year)
        ds3 = GetKeyDate("10/25", chkDate.Year)
        ds4 = GetKeyDate("11/01", chkDate.Year)

        If ((Date.Compare(chkDate, ds1) >= 0) And (Date.Compare(chkDate, ds2) < 0)) Or ((Date.Compare(chkDate, ds3) >= 0) And (Date.Compare(chkDate, ds4) < 0)) Then
            Return Not DST  'If the date is within one of these ranges, the result will be exactly wrong.
        Else
            Return DST
        End If
    End Function

Back to the top

REFERENCES

For more information about the Daylight Saving Time Help and Support Center, visit the following Microsoft Web site:
http://support.microsoft.com/gp/cp_dst (http://support.microsoft.com/gp/cp_dst)
For more information about Visual Studio and the DST change, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/vstudio/bb264729.aspx (http://msdn2.microsoft.com/en-us/vstudio/bb264729.aspx)

Back to the top


APPLIES TO
•Microsoft .NET Framework 2.0
•Microsoft .NET Framework 1.1
•Microsoft .NET Framework 1.0

Back to the top

Keywords: 
kbinfo kbtshoot kbcode kbpubtypekc KB933509

Back to the top

       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please