The CurrentUTC function will return the current time in UTC (Universal Time Coordinated) based on the system clock. It uses the IsDST function to determine whether or not Daylight Saving Time is in effect. Copy all of the following code into a global Module. You need to set the constant UTC_OFFSET for your area, for example Eastern Standard Time is normally UTC-5.
Code
Const UTC_OFFSET = -5 ' Eastern Standard Time (UTC-5)
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 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 PtrSafe Function GetTimeZoneInformation Lib "kernel32" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Public Function CurrentUTC() As Date
Dim Offset As Integer
Offset = UTC_OFFSET * -1
If IsDST() Then Offset = Offset - 1
CurrentUTC = DateAdd("h", Offset, Now())
End Function
Public Function IsDST() As Boolean
' 1 = Standard, 2 = Daylight, 0 = Unknown
Dim TZInfo As TIME_ZONE_INFORMATION
Dim L As Long
L = GetTimeZoneInformation(TZInfo)
If L = 2 Then
IsDST = True
Else
IsDST = False
End If
End Function