none
VBscript: how to get time zone offset?

    Question

  • I'd like to get the time zone, in UTC offset format, using VBscript. I did find this example script to get the offset VALUE, but I need the SIGN (i.e., - or +, depending), too.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone")
     
    For Each objTimeZone in colTimeZone
        Wscript.Echo "Offset: "& objTimeZone.Bias
    Next

    Is there any way to get the sign?

    The reason I need it is to refine event log queries for searching within a range of dates (e.g., I need August 5, 2009 to August 8, 2009 translated to 20090805000000.000000+540 and 20090808235959.000000+540, respectively). So, maybe if there's a better way to do that without needing the offset, that'd be great, too!

    • Edited by TheOneGuy Monday, August 10, 2009 4:11 AM typo
    Monday, August 10, 2009 4:11 AM

Answers

  • Hi,

    The sign is implicit--the Bias property returns negative values for time zones before GMT, and positive values for time zones after GMT. For example, a bias of -420 minutes means GMT -7, and a bias of 540 means GMT +9.

    HTH,

    Bill
    • Marked as answer by TheOneGuy Monday, August 10, 2009 5:35 AM
    Monday, August 10, 2009 4:44 AM
    Moderator

All replies

  • Hi,

    The sign is implicit--the Bias property returns negative values for time zones before GMT, and positive values for time zones after GMT. For example, a bias of -420 minutes means GMT -7, and a bias of 540 means GMT +9.

    HTH,

    Bill
    • Marked as answer by TheOneGuy Monday, August 10, 2009 5:35 AM
    Monday, August 10, 2009 4:44 AM
    Moderator
  • Ah, well, I should have known that. Yeesh.

    Thanks!
    Monday, August 10, 2009 5:35 AM