Date/Time Diff

  • Thread starter Thread starter Walter
  • Start date Start date
W

Walter

I would like to create a query that returns the diffrence
in time(Hrs,Min,Sec) between two fields that contain Date
time field formats as follows.


Start Date/Time - 9/12/03 5:30:00 PM
End Date/Time - 9/13/03 6:30:00 PM
Result - 25:00:00 hrs

Any help/direction would be greatly appreciated

(e-mail address removed)
 
Walter said:
I would like to create a query that returns the diffrence
in time(Hrs,Min,Sec) between two fields that contain Date
time field formats as follows.


Start Date/Time - 9/12/03 5:30:00 PM
End Date/Time - 9/13/03 6:30:00 PM
Result - 25:00:00 hrs

You could use a function in your query to return the elapsed time. Pass the two
date fields to this function.

Public Function getTimeBetweenString(dStartDate As Variant, _
dEndDate As Variant) As String
Const cMinutes As Long = 60
Const cHour As Long = 60 * 60

Dim nSecs As Long, nMinutes As Long, nHours As Long

getTimeBetweenString = vbNullString

If isDate(dStartDate) and isDate(dEndDate) Then
nSecs = DateDiff("s", dStartDate, dEndDate)
nHours = nSecs \ cHour
nMinutes = nSecs Mod cHour
nSecs = nSecs Mod cMinutes

getTimeBetweenString = nHours & ":" & nMinutes & ":" & nSecs
End If

End Function
 
Back
Top