bgarey said:
I have a list of times starting with zero in a table as shown below:
0 0:00:00
1 0:12:33
2 0:15:36
3 0:18:02
and so on.
I need to set up in a query or form, etc. a way to find the difference in
sequential times as shown below:
0 0:00:00
1 0:12:33 0:12:33
2 0:15:36 0:03:03
3 0:18:48 0:03:12
Any help?
Sharkbyte's idea should work. Alternatively, I tried this using a
string for TimeValue and found it interesting.
tblTimes
TimeID TimeNumber TimeValue (Text)
1 0 0:00:00
2 1 0:12:33
3 2 0:15:36
4 3 0:18:48
If the TimeNumber values all increase by 1 (else use TimeID) try:
qryTimes:
SELECT TimeNumber, TimeValue, (SELECT A.TimeValue FROM tblTimes AS A
WHERE A.TimeNumber = tblTimes.TimeNumber - 1) AS PrevTimeValue,
(Hour(TimeValue) - Hour(PrevTimeValue)) * 3600 + (Minute(TimeValue) -
Minute(PrevTimeValue)) * 60 + Second(TimeValue) - Second(PrevTimeValue)
AS ElapsedSeconds, ElapsedSeconds \ 3600 AS theHours, ElapsedSeconds \
60 - 60 * theHours AS theMinutes, ElapsedSeconds - 60 * theMinutes -
3600 * theHours AS theSeconds, IIf(IsNull(theHours), Null, theHours &
':' & Format(theMinutes, '00') & ':' & Format(theSeconds, '00')) AS
Difference FROM tblTimes;
!qryTimes:
TimeNumber ... Difference
0 Null
1 0:12:33
2 0:03:03
3 0:03:12
James A. Fortune