How can I retrieve GMTwithout calculating it in Access 2003?

  • Thread starter Thread starter Dick3425
  • Start date Start date
D

Dick3425

I need Greenwhich Mean time in order to caculate and display the time in
different time zones.
 
Option Compare Database
Option Explicit

Public 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 Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 31) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 31) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

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

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

Private Declare Function SystemTimeToTzSpecificLocalTime _
Lib "kernel32" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION, _
lpUniversalTime As SYSTEMTIME, _
lpLocalTime As SYSTEMTIME _
) As Long

Private Declare Function TzSpecificLocalTimeToSystemTime _
Lib "kernel32" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION, _
lpLocalTime As SYSTEMTIME, _
lpUniversalTime As SYSTEMTIME _
) As Long

Private Declare Function GetTimeZoneInformation _
Lib "kernel32" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION _
) As Long

Public Function LocalToUTC(ByVal dtLocal As Date) As Date
Const cMinsPerDay = 1440
Dim tzi As TIME_ZONE_INFORMATION
Dim stUTC As SYSTEMTIME
Dim stLocal As SYSTEMTIME
Dim dtUTC As Date
Dim lRes As Long
lRes = GetTimeZoneInformation(tzi)
#If Pre_WinXP Then
dtUTC = dtLocal + tzi.Bias / cMinsPerDay
If tzi.StandardDate.wMonth <> 0 Then
' timezone has daylight saving
If Int(UTCtoLocal(dtUTC) * cMinsPerDay) <> Int(dtLocal * cMinsPerDay) Then
' we are in DST
dtUTC = dtUTC + tzi.DaylightBias / cMinsPerDay
End If
End If
#Else
stLocal = DateTimeToSystemTime(dtLocal)
lRes = TzSpecificLocalTimeToSystemTime(tzi, stLocal, stUTC)
dtUTC = SystemTimeToDateTime(stUTC)
#End If
LocalToUTC = dtUTC
End Function

Public Function SystemTimeToDateTime(t As SYSTEMTIME) As Date
Const cMsPerDay = 86400000#
SystemTimeToDateTime = DateSerial(t.wYear, t.wMonth, t.wDay) _
+ TimeSerial(t.wHour, t.wMinute, t.wSecond) _
+ (t.wMilliseconds / cMsPerDay)
End Function

Public Function DateTimeToSystemTime(tDate As Date) As SYSTEMTIME
With DateTimeToSystemTime
.wYear = Year(tDate)
.wMonth = Month(tDate)
.wDay = Day(tDate)
.wHour = Hour(tDate)
.wMinute = Minute(tDate)
.wSecond = Second(tDate)
.wMilliseconds = 0
End With
End Function
*********
=LocalToUTC(Now) or whatevertime you wan't converted.
 
Back
Top