Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle Time ?

Status
Not open for further replies.

hoym

Technical User
Sep 14, 2002
15
HK
I know that is a function dateadd & datediff in Access to handle DATE ; but is it any similar functions for manageing TIME ?
 
Here's a function to calculate the difference between two Date/Time fields. As written, it will return days, hours and minutes.
Code:
Public Function TimeElapsed(dIn As Variant, dOut As Variant) As String
    If dOut - dIn > 0 Then
        TimeElapsed = CStr(Int(Format(dOut - dIn, "General Number"))) & " Day(s) " & DatePart("h", dOut - dIn) & " Hour(s) " & DatePart("n", dOut - dIn) & " Minute(s)"
    Else
        TimeElapsed = ""
    End If
End Function

To show a time calculation in a decimal representation of hours, i.e. 09/16/02 07:00 to 09/16/02 15:30 = 8.5 hours, try this:
Code:
Public Function TimeElapsed(dIn As Variant, dOut As Variant) As Double
    If dOut - dIn > 0 Then
        TimeElapsed = ((CInt(Int(Format(dOut - dIn, "General Number"))) * 24) + DatePart("h", dOut - dIn)) + (DatePart("n", dOut - dIn) / 60)
    Else
        TimeElapsed = ""
    End If
End Function
In your query, add a field something like this:
Code:
ElapsedTime: TimeElapsed([TimeFieldIn],[TimeFieldOut])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top