27 minutes
ago: Please note that the webserver will soon get its weekly reboot at 4:00 am Eastern Time. You may continue to use the site as normal, but you will be logged off at that time. You should be able to log right back on immediately, however. If you are in the process of placing an order, please make sure to complete it as quickly as possible, or come back after the reboot. Thank you. Sorry for any inconvenience.
Dismiss
The purpose of education is to show people how to learn for themselves. The other part of it is that you need to reach that state of independence and self-reliance.
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