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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Total 2

Status
Not open for further replies.

Weezy

Technical User
Dec 29, 1999
2
US
Is it possible to enter a &quot;start time&quot; and &quot;end time&quot; in Access and have it calculate the total time duration? i.e. say you are an appliance repairman and you want to track the amount of time spent on specific service calls as part of the database. So on the Access form you enter the time arrived and the time departed; Can Access then calculate the total duration of the visit automatically and display the result?<br>
Thanks in advance<br>
Steve
 
This is probably overkill but:<br>
<br>
'**************************************************************<br>
' Public Function ElapsedTimeLong(dStart, dEnd)<br>
' Calculate the time elapsed from dStart to dEnd and return the<br>
' result as a string that looks like the following example:<br>
' &quot;10 days, 20 hours, 30 minutes, 40 seconds&quot;. Zero values are<br>
' excluded. '***********************************************<br>
Public Function ElapsedTimeLong(dStart, dEnd) As String<br>
Dim dInterval As Double, sElapsed As String<br>
Dim sD As Variant, sH As String, sM As String, sS As String<br>
<br>
dInterval = dEnd - dStart ' Calculate the difference<br>
sD = Int(CSng(dInterval)) ' Days<br>
sH = Format(dInterval, &quot;h&quot;) ' Hours<br>
sM = Format(dInterval, &quot;n&quot;) ' Minutes<br>
sS = Format(dInterval, &quot;s&quot;) ' Seconds ' Construct days<br>
sElapsed = IIf(sD = 0, &quot;&quot;, IIf(sD = 1, sD & &quot; Day&quot;, sD & &quot; Days&quot;))<br>
sElapsed = sElapsed & IIf(sD = 0, &quot;&quot;, IIf(sH & sM & sS = &quot;000&quot;, &quot;, &quot;, &quot; &quot;))<br>
' Construct hours<br>
sElapsed = sElapsed & IIf(sH = &quot;0&quot;, &quot;&quot;, IIf(sH = &quot;1&quot;, sH & &quot; Hour&quot;, sH & &quot; Hours&quot;))<br>
sElapsed = sElapsed & IIf(sH = &quot;0&quot;, &quot;&quot;, IIf(sM & sS = &quot;00&quot;, &quot;, &quot;, &quot; &quot;))<br>
' Construct minutes<br>
sElapsed = sElapsed & _<br>
IIf(sM = &quot;0&quot;, &quot;&quot;, IIf(sM = &quot;1&quot;, sM & &quot; Minute&quot;, sM & &quot; Minutes&quot;))<br>
sElapsed = sElapsed & IIf(sM = &quot;0&quot;, &quot;&quot;, IIf(sS = &quot;0&quot;, &quot;, &quot;, &quot; &quot;))<br>
' Construct seconds<br>
sElapsed = sElapsed & IIf(sS = &quot;0&quot;, &quot;&quot;, IIf(sS = &quot;1&quot;, sS & &quot; Second&quot;, sS & &quot; Seconds&quot;))<br>
' Assign for return to caller<br>
ElapsedTimeLong = IIf(sElapsed = &quot;&quot;, &quot;0&quot;, sElapsed)<br>
<br>
End Function<br>
<br>
HTH<br>
RDH
 
It is WAY overkill<br>
Look at the &quot;DateDiff&quot; function<br>
<br>
here is a Help example<br>
<br>
Dim TheDate As Date ' Declare variables.<br>
Dim Msg<br>
TheDate = InputBox(&quot;Enter a date&quot;)<br>
Msg = &quot;Days from today: &quot; & DateDiff(&quot;d&quot;, Now, TheDate)<br>
MsgBox Msg<br>
<br>
you can change the &quot;d&quot; to &quot;s&quot; to get seconds or any other time frame<br>
keep in mind that miniutes is &quot;n&quot; ont &quot;m&quot; <br>
because &quot;m&quot; is for months<br>
<br>

 
Or just create a form with 3 textboxes:<br>
txtStart (format property = short time)<br>
txtEnd (format property = short time)<br>
txtDiff, unformatted, OnEnter event contains:<br>
txtDiff = DateDiff(&quot;h&quot;, txtStart, txtEnd) & &quot;:&quot; & DateDiff(&quot;n&quot;, txtStart, txtEnd) Mod 60
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top