Calculating elapsed time

G

Guest

I am trying to calculate difference between two different times and
everything is ok if times are from am to pm on a same day. How do I
calculate elapsed time between for example 02/14 10:20 pm and 02/16 9:30 pm?
I created 2 text boxes (day in and day out) where I select specific date from
a calendar. Then I have to more text boxes for time (time in and time out) I
also would like to display result in a text box in format for ex. The
difference is: 1 day 4 hours and 20 min. Thanks
 
F

fredg

I am trying to calculate difference between two different times and
everything is ok if times are from am to pm on a same day. How do I
calculate elapsed time between for example 02/14 10:20 pm and 02/16 9:30 pm?
I created 2 text boxes (day in and day out) where I select specific date from
a calendar. Then I have to more text boxes for time (time in and time out) I
also would like to display result in a text box in format for ex. The
difference is: 1 day 4 hours and 20 min. Thanks

All you need is one field for In and one field for Out.
You'll get accurate elapsed time if you include the full date as well
as the time of day in each field, i.e. Time in = 2/14/2007 10:20 PM

To get days, hours, and minutes in one function see:
"A More Complete DateDiff Function" at
http://www.accessmvp.com/djsteele/Diff2Dates.html

? Diff2Dates("dhn",#2/14/2007 10:20 PM#,#2/16/2007 9:20 AM#,True)
1 day 11 hours 0 minutes
 
G

Guest

The following function will give you the elapsed time between two date/time
values either in the format h:nn:ss or, by means of the optional blnShowDays
atgument, d days hh:nn:ss

Public Function TimeDuration( _
dtmFrom As Date, _
dtmTo As Date, _
Optional blnShowDays As Boolean = False) As String

Const HOURSINDAY = 24
Dim lngHours As Long
Dim strMinutesSeconds As String
Dim strDaysHours As String
Dim dblDuration As Double

dblDuration = dtmTo - dtmFrom

'get number of days
lngHours = Int(dblDuration) * HOURSINDAY + _
Format(dblDuration, "h")

' get minutes and seconds
strMinutesSeconds = Format(dblDuration, ":nn:ss")

If blnShowDays Then
'get days and hours
strDaysHours = lngHours \ HOURSINDAY & _
" day" & IIf(lngHours \ HOURSINDAY <> 1, "s ", " ") & _
lngHours Mod HOURSINDAY

TimeDuration = strDaysHours & strMinutesSeconds
Else
TimeDuration = lngHours & strMinutesSeconds
End If

End Function

So:

TimeDuration(#02/17/2007 10:15:45#, #02/19/2007 18:33:50#)

returns 56:18:05

and:

TimeDuration(#02/17/2007 10:15:45#, #02/19/2007 18:33:50#, True)

returns 2 days 8:18:05

In your case just make the ControlSource of the third text box:

= TimeDuration([Day In]+[Time In], [Day Out]+[Time Out], True)

Ken Sheridan
Stafford, England
 

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

Top