How to get UTC time in Access

  • Thread starter Thread starter Joy
  • Start date Start date
J

Joy

Is there a function to
get UTC time in Access,like getUTCDate()
in SQL-Server ?

thx in advance.
 
Joy:

No, there isn't any built in function in Access to get a UTC time. However,
you can get a UTC time by using api calls. Here's the function(s) to do so.
Call the UTCTimeConvert function below to get a UTC time.

HTH
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

'-------------beginn code-------------

Option Explicit

Private Declare Sub GetSystemTime Lib "kernel32" (pST As SYSTEM_TIME)
Private Declare Function SystemTimeToFileTime2 Lib "kernel32" Alias
"SystemTimeToFileTime" (pST As SYSTEM_TIME, pFT As Currency) As Long
Private Declare Function GetSystemTimeAsFileTime Lib "kernel32" (lpFileTime
As Any) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpSysFT As
Any, lpLocalFT As Any) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA"
(lpOSInfo As OSVERSIONINFO) As Boolean
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEM_TIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Long
End Type
Private Type TIME_ZONE
Bias As Long
StandardName(0 To 63) As Byte
StandardDate As SYSTEM_TIME
StandardBias As Long
DaylightName(0 To 63) As Byte
DaylightDate As SYSTEM_TIME
DaylightBias As Long
End Type
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
strReserved As String * 128
End Type
Public Function UTCTimeConvert(ByVal varInput As Date) As Variant
On Error Resume Next
'Need to use Currency data type for long 64 bit values
Dim varST As SYSTEM_TIME, curFileTime As Currency, curLocalFileTime As
Currency
Dim dwReturn As Long, ds As Date
Const VER_WIN32_WINDOWS_NT = 2
Call GetSystemTime(varST)
If atWinver(0) = VER_WIN32_WINDOWS_NT Then
dwReturn = SystemTimeToFileTime2(varST, curFileTime)
UTCTimeConvert = curFileTime
Else
dwReturn = GetSystemTimeAsFileTime(curFileTime)
dwReturn = FileTimeToLocalFileTime(curFileTime, curLocalFileTime)
UTCTimeConvert = curLocalFileTime
End If

End Function
Private Function atWinver(OSorVer As Byte) as Byte
Dim osinfo As OSVERSIONINFO
osinfo.dwOSVersionInfoSize = Len(osinfo)
If GetVersionEx(osinfo) Then
If OSorVer = 0 Then
atWinver = osinfo.dwPlatformId
Else
atWinver = osinfo.dwMajorVersion
End If
Else
atWinver = 0
End If
End Function
 
Back
Top