Retrieving time difference between time zones

Posted on 2005-05-09
Last Modified: 2010-07-27

How do I determine how many hours my system clock is behind or infront of the time in London? I'm sure the last time I attempted to get this information, I was stopped short in my tracks by whether it was GMT or BST (+1 hour). I also know that when clocks go forward or backwards by an hour due to daylight saving, there can be a wait of a week or so for time zones to sync up.

Thanks in advance...
Question by:cartti
    LVL 76

    Expert Comment

    LVL 13

    Expert Comment

    This also may help:

    Option Explicit

    Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
    Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

    Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
    End Type

    Private Sub Form_Load()

        MsgBox "Current time in london (no daylight saving): " + CStr(GetSystemTimeVB) + vbCrLf + _
        "Current time here (with daylight saving): " + CStr(GetLocalTimeVB) + vbCrLf

    End Sub

    Private Function GetSystemTimeVB() As Date

        Dim SysTime As SYSTEMTIME

        GetSystemTime SysTime
        GetSystemTimeVB = DateSerial(SysTime.wYear, SysTime.wMonth, SysTime.wDay) + TimeSerial(SysTime.wHour, SysTime.wMinute, SysTime.wSecond)

    End Function

    Private Function GetLocalTimeVB() As Date

        Dim SysTime As SYSTEMTIME

        GetLocalTime SysTime
        GetLocalTimeVB = DateSerial(SysTime.wYear, SysTime.wMonth, SysTime.wDay) + TimeSerial(SysTime.wHour, SysTime.wMinute, SysTime.wSecond)

    End Function
    LVL 2

    Author Comment

    Thanks rettiseert, that's certainly useful. Though how would I determine if it's GMT or BST in London (without hardcoding the dates)?
    LVL 27

    Accepted Solution

    See my sample at <<Convert Times Across Different Time Zones>>
    LVL 2

    Author Comment

    That's brilliant Ark, exactly what I was looking for. Thanks to all for your help!
    LVL 27

    Expert Comment

    Thanks for points, glad I could help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now