To subtract 6 hours, use DateAdd. You won't need TimeValue for that. Using
DateAdd will make the date/time fields calculated fields also.
Example:
SELECT LoginLogout.LogTime
would be
SELECT DateAdd("h", -6, [LoginLogout].[LogTime]) As LoginTime
However, this will change depending on whether or not you're currently in
Daylight Savings Time. There is a Windows API call you can make to determine
whether or not you are currently in DST and adjust the difference
accordingly.
Private Declare Function GetTimeZoneInformation Lib "kernel32"
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
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 63) As Byte
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Private Const TIME_ZONE_ID_UNKNOWN = 0
Private Const TIME_ZONE_ID_STANDARD = 1
Private Const TIME_ZONE_ID_DAYLIGHT = 2
Public Sub TimeInfo()
Dim nRet As Long
Dim tz As TIME_ZONE_INFORMATION
nRet = GetTimeZoneInformation(tz)
If nRet <> TIME_ZONE_ID_INVALID And nRet <> TIME_ZONE_ID_UNKNOWN Then
Debug.Print "Current Bias: " & tz.Bias / 60 - (nRet - 1)
End If
End Sub
The bias will give you the amount of time to add to the local time to reach
UTC (in minutes). Divide by 60 to get hours. If you are daylight time nRet
will be 2, standard time nRet will be 1. Subtract 1 from this value then
subtract that from the bias to get the current bias (daylight or standard
time).
--
Wayne Morgan
MS Access MVP
Scottie said:
Wayne,
I think that I figured out the syntax. Here is what I came up with and
the results.
SELECT LoginLogout.LogTime, DMin("LogTime","LoginLogout","LogTime >= #"
& [LogTime] & "# And UserName = """ & [UserName] & """ And LoginOutCode
= 4") AS LogOut, DateDiff("s",[LogTime],[LogOut]) AS ElapsedTime,
LoginLogout.UserName, LoginLogout.LoginOutCode
FROM LoginLogout
WHERE (((LoginLogout.UserName)="msp2sxs") AND
((LoginLogout.LoginOutCode)=2));
LogTime LogOut ElapsedTime UserName LoginOutCode
12/22/2005 3:16:38 AM 12/22/2005 3:20:38 AM 240 MSP2SXS
2
12/22/2005 3:21:54 AM 12/22/2005 3:25:42 AM 228 MSP2SXS
2
12/22/2005 3:27:55 AM 12/22/2005 3:34:49 AM 414 MSP2SXS
2
12/22/2005 5:39:47 AM 12/22/2005 5:48:54 AM 547 MSP2SXS
2
12/22/2005 5:49:04 AM 12/22/2005 5:52:16 AM 192 MSP2SXS
2
12/22/2005 5:49:22 AM 12/22/2005 5:52:16 AM 174 MSP2SXS
2
My times are in GMT, so they are off by 6 hours. How do I subtract 6
hours from these timestamps? Do I need to use TimeValue and then
DateAdd?
Scott