Link to home
Start Free TrialLog in
Avatar of blueskybooking
blueskybookingFlag for Canada

asked on

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

Avatar of graye
graye
Flag of United States of America image

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 
ASKER CERTIFIED SOLUTION
Avatar of blueskybooking
blueskybooking
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blueskybooking

ASKER

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