Date/Time Diff

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)
 
J

John Mishefske

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top