Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


October 09, 2006

Don't Let Daylight Saving Time Sneak Up on You

Script determines when those fateful Sundays occur
RSS
Subscribe to Windows IT Pro | See More VBScript Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
SideBar    Daylight Saving Time Is Changing in 2007

Download the Code Here

I'm always caught off guard when that fateful Sunday rolls around when time either springs ahead or falls back an hour. The hour backward in fall isn't so bad. Although it still sneaks up on me, I don't mind having an extra hour to sleep or just relax. But that Sunday in early spring when I have to get up an hour earlier is a killer.

To make these new dates less of a rude awakening, I wrote a script named GetDLSDates.vbs. By simply double-clicking the script, I get a reminder of when daylight saving time begins and ends in the current year. Without having to change any code, this script will work the same year after year, even given the upcoming changes in daylight saving time. (For information about these changes, see the sidebar "Daylight Saving Time Is Changing in 2007.")

GetDLSDates.vbs uses Windows Management Instrumentation's (WMI's) Win32_TimeZone class to access information about the time zone and daylight saving time properties in a Windows OS. Thus, to understand how the script works, you need to know what several Win32_TimeZone class properties represent.

The Win32_TimeZone Class Properties
GetDLSDates.vbs relies on the following Win32_TimeZone class properties:

  • Bias. The Bias property represents the difference in minutes between Greenwich Mean Time (GMT—also known as Coordinated Universal Time, or UTC) and local time. For example, Eastern time (US and Canada) has a Bias property value of -300. You can also find the bias represented in hours instead of minutes. For example, Windows' Date and Time Properties dialog box shows the bias between Eastern time and GMT as -05:00, which means GMT minus 5 hours.
  • DaylightBias. The DaylightBias property is the offset value used when the Windows clock is set to automatically adjust for daylight saving time. In the Win32_Time-Zone class documentation, Microsoft states that the DaylightBias property value is added to the Bias property value to form the bias used during daylight saving time. The term "added" can be confusing. In most time zones, the DaylightBias property has a value of -60 minutes. If you add the DaylightBias property value to the Bias property value, you'll get a wrong value, such as
    -300 + -60 = -360
    However, if you subtract the DaylightBias property value from the Bias property value, you get the correct value
    -300 - -60 = -240 
    because the double negative translates into a positive number:
    -300 +60 = -240 
    In this sense, you could say that you're adding the DaylightBias value to the Bias value.
  • StandardBias. The StandardBias property is used to determine the bias when daylight saving time isn't in effect. It typically has the value of 0.
  • DaylightMonth and Standard-Month. The DaylightMonth property represents the month in which daylight saving time starts, whereas the StandardMonth property represents the month in which daylight saving time ends. The possible values for both properties range from 1 to 12 and represent the corresponding months of the year. For example, when daylight saving time begins in April, the Daylight-Month property has a value of 4. When daylight saving time ends in October, the StandardMonth property has a value of 10.
  • DaylightDayOfWeek and Standard-DayOfWeek. The DaylightDay-OfWeek property represents the day of the week when daylight saving time starts. Its counterpart, StandardDayOfWeek, represents the day of the week when daylight saving time ends. The possible value ranges for both properties are 0 through 6, with 0 representing Sunday and 6 representing Saturday. Typically, both values are set to 0 (Sunday).
  • DaylightDay and StandardDay. The DaylightDay property represents the first (value of 1), second (2), third (3), fourth (4), or fifth (5) occurrence of the day specified by DaylightDayOfWeek. The Standard-Day property has the same usage and values as DaylightDay, except it indicates the first, second, third, fourth, or fifth occurrence of StandardDayOfWeek. So, for example, when daylight saving time begins on the first Sunday of April, the DaylightDay property would have a value of 1. When daylight saving time ends the last Sunday of October, the StandardDay property would have a value of 4 or 5, depending on when October 1 falls. For example, this year October 1 fell on a Sunday, so the last Sunday of the month is the fifth occurrence (i.e., StandardDay = 5).
  • DaylightHour and StandardHour. The DaylightHour and Standard-Hour properties specify the hour of the day that daylight saving time begins and ends, respectively. In most cases, these property values are set to the value 2, which represents 2 A.M.
  • DaylightMinute and Standard-Minute. The DaylightMinute and StandardMinute properties specify the minute of the day that daylight saving time begins and ends, respectively. In most cases, these property values are set to the value of 0.
  • DaylightName and StandardName. The DaylightName property contains a string value that specifies the time-zone name when daylight saving time is in effect (e.g., Eastern Daylight Time). The StandardName property's string value specifies the time-zone name when daylight saving time isn't in effect (e.g., Eastern Standard Time).

Now that you know about the importantWin32_TimeZone class properties, let's take a look at how GetDLSDates-.vbs uses them.

   Previous  [1]  2  3  Next 


Top Viewed ArticlesView all articles
Anti-Virus Vendors Prepare for War with Microsoft ... Again

When Microsoft announced its Windows Live OneCare security and PC health product over five years (as MSN OneCare), Symantec, McAfee, and the other consumer-oriented security vendors reacted with stunning vigor. ...

What You Need to Know About Microsoft's x64 Server Product Plans

What do Longhorn Server, Windows Compute Cluster Server, and Windows Vista have in common? The x64 platform. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...


Related Events WinConnections and Microsoft® Exchange Connections

The Easiest Way to Save Time and Money on E-mail and SharePoint Management

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing