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
Command Prompt Tricks

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

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events 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


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
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement