Solved

SQL Registry Lookup : TZI Bias

Posted on 2010-09-18
5
734 Views
Last Modified: 2012-05-10
The following outputted "Bias" does not appear to take into account Daylight Savings Time when executed on SQL 2008.  The simplicity of the code is great, but it doesn't appear to get the current Bias.  I changed the clock on my machine, restarted SQL Server, but I did not reboot my machine when I tested.
DECLARE @TZIBias int

EXECUTE master.dbo.xp_regread
  'HKEY_LOCAL_MACHINE',
  'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Pacific Standard Time',
  'TZI',
  @TZIBias OUTPUT

SELECT @TZIBias

Open in new window

0
Comment
Question by:Officedoxs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 41

Expert Comment

by:graye
ID: 33715892
Yeah, the government has been messing with the start/stop dates of Daylight Saving Time (that's why there is a Dynamic DSL key at that location)
To make things easier, I'd recommend that you use a VB.Net or C# CLR Storage Procedure.  The link below is an example:
http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-programming/39935/SQL-Server-and-Time-Zome 
0
 

Accepted Solution

by:
Officedoxs earned 0 total points
ID: 33721015
That got me going, I was able to extract from the registry using VBScript.  However, I'm having problem with one of the TZI fields.  Looks like I have a formatting problem with the Bias, StandardBias and DaylightBias.  Sometimes it works, sometimes it's a minute off.  Something with how I am adding up the values...




' http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/

const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set StdOut = WScript.StdOut
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Pacific Standard Time"
'strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Myanmar Standard Time"
'strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Tasmania Standard Time"
'strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Jordan Standard Time"

strValueName = "TZI"
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue
 
StdOut.Write "Bias                       : " & -(strValue( 0) + (256 * strValue( 1))) + (strValue( 2) + (256 * strValue( 3))) & vbCrLf
StdOut.Write "StandardBias               : " & -(strValue( 4) + (256 * strValue( 5))) + (strValue( 6) + (256 * strValue( 7))) & vbCrLf
StdOut.Write "DaylightBias               : " & -(strValue( 8) + (256 * strValue( 9))) + (strValue(10) + (256 * strValue(11))) & vbCrLf

StdOut.Write "StandardDate (Year)        : " & (strValue(12) + (256 * strValue(13))) & vbCrLf
StdOut.Write "StandardDate (Month)       : " & (strValue(14) + (256 * strValue(15))) & vbCrLf
StdOut.Write "StandardDate (DayOfWeek)   : " & (strValue(16) + (256 * strValue(17))) & vbCrLf
StdOut.Write "StandardDate (Day)         : " & (strValue(18) + (256 * strValue(19))) & vbCrLf
StdOut.Write "StandardDate (Hour)        : " & (strValue(20) + (256 * strValue(21))) & vbCrLf
StdOut.Write "StandardDate (Minute)      : " & (strValue(22) + (256 * strValue(23))) & vbCrLf
StdOut.Write "StandardDate (Second)      : " & (strValue(24) + (256 * strValue(25))) & vbCrLf
StdOut.Write "StandardDate (Milliseconds): " & (strValue(26) + (256 * strValue(27))) & vbCrLf

StdOut.Write "DaylightDate (Year)        : " & (strValue(28) + (256 * strValue(29))) & vbCrLf
StdOut.Write "DaylightDate (Month)       : " & (strValue(30) + (256 * strValue(31))) & vbCrLf
StdOut.Write "DaylightDate (DayOfWeek)   : " & (strValue(32) + (256 * strValue(33))) & vbCrLf
StdOut.Write "DaylightDate (Day)         : " & (strValue(34) + (256 * strValue(35))) & vbCrLf
StdOut.Write "DaylightDate (Hour)        : " & (strValue(36) + (256 * strValue(37))) & vbCrLf
StdOut.Write "DaylightDate (Minute)      : " & (strValue(38) + (256 * strValue(39))) & vbCrLf
StdOut.Write "DaylightDate (Second)      : " & (strValue(40) + (256 * strValue(41))) & vbCrLf
StdOut.Write "DaylightDate (Milliseconds): " & (strValue(42) + (256 * strValue(43))) & vbCrLf


For i = LBound(strValue) to UBound(strValue)
  strTZIHex = strTZIHex & Right("00" & Hex(strValue(i)), 2) & ":"
  strTZI = strTZI & strValue(i) & ":"
Next

StdOut.Write "TZI (Hex): " & vbCrLf & strTZIHex & vbCrLf
StdOut.Write "TZI      : " & vbCrLf & strTZI & vbCrLf

MsgBox "Completed"

---

Results for Pacific Standard Time:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Bias                       : -480
StandardBias               : 0
DaylightBias               : 59 ***
StandardDate (Year)        : 0
StandardDate (Month)       : 11
StandardDate (DayOfWeek)   : 0
StandardDate (Day)         : 1
StandardDate (Hour)        : 2
StandardDate (Minute)      : 0
StandardDate (Second)      : 0
StandardDate (Milliseconds): 0
DaylightDate (Year)        : 0
DaylightDate (Month)       : 3
DaylightDate (DayOfWeek)   : 0
DaylightDate (Day)         : 2
DaylightDate (Hour)        : 2
DaylightDate (Minute)      : 0
DaylightDate (Second)      : 0
DaylightDate (Milliseconds): 0
TZI (Hex):
E0:01:00:00:00:00:00:00:C4:FF:FF:FF:00:00:0B:00:00:00:01:00:02:00:00:00:00:00:00
:00:00:00:03:00:00:00:02:00:02:00:00:00:00:00:00:00:
TZI      :
224:1:0:0:0:0:0:0:196:255:255:255:0:0:11:0:0:0:1:0:2:0:0:0:0:0:0:0:0:0:3:0:0:0:2
:0:2:0:0:0:0:0:0:0:

Results for Jordan Standard Time:

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Bias                       : 119 ***
StandardBias               : 0
DaylightBias               : 59 ***
StandardDate (Year)        : 0
StandardDate (Month)       : 10
StandardDate (DayOfWeek)   : 5
StandardDate (Day)         : 5
StandardDate (Hour)        : 1
StandardDate (Minute)      : 0
StandardDate (Second)      : 0
StandardDate (Milliseconds): 0
DaylightDate (Year)        : 0
DaylightDate (Month)       : 3
DaylightDate (DayOfWeek)   : 4
DaylightDate (Day)         : 5
DaylightDate (Hour)        : 23
DaylightDate (Minute)      : 59
DaylightDate (Second)      : 59
DaylightDate (Milliseconds): 999
TZI (Hex):
88:FF:FF:FF:00:00:00:00:C4:FF:FF:FF:00:00:0A:00:05:00:05:00:01:00:00:00:00:00:00
:00:00:00:03:00:04:00:05:00:17:00:3B:00:3B:00:E7:03:
TZI      :
136:255:255:255:0:0:0:0:196:255:255:255:0:0:10:0:5:0:5:0:1:0:0:0:0:0:0:0:0:0:3:0
:4:0:5:0:23:0:59:0:59:0:231:3:

Open in new window

0
 

Author Comment

by:Officedoxs
ID: 33721329
Was able to make it work with the following adjustments to the script.
StdOut.Write "Bias                       : " & mBias(strValue(0), strValue(1), strValue(2), strValue(3)) & vbCrLf
StdOut.Write "StandardBias               : " & mBias(strValue(4), strValue(5), strValue(6), strValue(7)) & vbCrLf
StdOut.Write "DaylightBias               : " & mBias(strValue(8), strValue(9), strValue(10), strValue(11)) & vbCrLf

...

Function mBias(intValue1, intValue2, intValue3, intValue4)
  mBias = -(intValue1 + (256 * intValue2))
  If intValue3 > 0  or intValue4 > 0 Then
    mBias = mBias + 1 + (intValue3 + (256 * intValue4))
  End If
End Function

Open in new window

0

Featured Post

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question