Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time functions

0 views
Skip to first unread message

Louis M. Garvin

unread,
Jul 23, 1999, 3:00:00 AM7/23/99
to
How do I get the time of day for each of the 4 US time zones?


Rick Rothstein

unread,
Jul 26, 1999, 3:00:00 AM7/26/99
to
Paste the following into a BAS Module (Project/AddModule from VB's menu
bar):

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

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

Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Function TimeInZone(ByVal TimeZone As String) As Variant
Dim TZ As TIME_ZONE_INFORMATION
Dim TimeZoneBias As Integer
TimeZone = UCase(Left$(TimeZone, 1))
GetTimeZoneInformation TZ
TimeZoneBias = TZ.Bias \ 60
Select Case TimeZone
Case "E"
TimeInZone = DateAdd("h", TimeZoneBias - 5, Now)
Case "C"
TimeInZone = DateAdd("h", TimeZoneBias - 6, Now)
Case "M"
TimeInZone = DateAdd("h", TimeZoneBias - 7, Now)
Case "P"
TimeInZone = DateAdd("h", TimeZoneBias - 8, Now)
Case "A"
TimeInZone = DateAdd("h", TimeZoneBias - 9, Now)
Case "H"
TimeInZone = DateAdd("h", TimeZoneBias - 10, Now)
Case Else
TimeInZone = -1
Exit Function
End Select
TimeInZone = Format$(TimeInZone, "Long Time")
End Function


This function (TimeInZone) is called with a single parameter -- the first
letter of the US time zone. You can, internal self-documenting purposes,
provide more of the time zone's name if you wish, but anything you type
after the first letter is ignored (and will *not* be checked for accuracy).

By the way, this function will respond to all US time zones; those being:
Eastern, Central, Mountain, Pacific, Alaska, Hawaii.

Rick


Louis M. Garvin wrote in message ...

0 new messages