I am trying to calculate "Start time" + "End Time" on a form in ACCESS 2007
example: I started @ 3:00 am on tuesday and did not finishish until 5:00 pm
on saturday.
How do I make a calculaution to give me a total for this?
what fields should be included in the datasheet and the form?
Craig G.,
You cannot perform a "Start Time" + "End Time" operation, not if "Start Time" and "End
Time" are Datetime values.
You can subtract them, "End Time" - "Start Time".
In VBA, you would do this:
Public Function ElapsedTimeFromDatetimes(StartDatetime As Date _
, EndDatetime As Date) As String
Dim TotalSeconds As Integer
Dim ElapsedHours As Integer
Dim ElapsedMinutes As Integer
Dim ElapsedSeconds As Integer
TotalSeconds = DateDiff("s", StartDatetime, EndDatetime)
ElapsedHours = TotalSeconds \ 3600
ElapsedMinutes = (TotalSeconds \ 60) Mod 60
ElapsedSeconds = TotalSeconds Mod 60
ElapsedTime = Format(CStr(ElapsedHours), "00") & ":" & _
Format(CStr(ElapsedMinutes), "00") & ":" & _
Format(CStr(ElapsedSeconds), "00")
ElapsedTimeFromDatetimes = ElapsedTime
End Function
The function call would appear as:
ElapsedTimeFromDatetimes([StartDatetime], [EndDatetime])
In a single expression, you would use:
Format(DateDiff("s", [StartDatetime], [EndDatetime]) \ 3600, "00") & ":" &
Format(DateDiff("s", [StartDatetime], [EndDatetime]) \ 60 MOD 60, "00") & ":" &
Format(DateDiff("s", StartDatetime], [EndDatetime]) MOD 60, "00")
Sincerely,
Chris O.