• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

SQL Registry Lookup : TZI Bias

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
Officedoxs
Asked:
Officedoxs
  • 2
1 Solution
 
grayeCommented:
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
 
OfficedoxsAuthor Commented:
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
 
OfficedoxsAuthor Commented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now