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!

Time Calculations 1

Status
Not open for further replies.

cell0042

Programmer
Nov 5, 2002
16
US
I want to be able to do a time calculation that will not let the minutes go over 60. Right I have the get the difference of two times to be something like 10.75 hrs. I want it to be like 10 and 45 minutes. Can I please get some help!!!!!
 
I wrote you a little function to do what you want. Pass it a double and it will return a string. Modify it any way you need to.

Public Function ConvertToTime(InNumber As Double) As String
Dim hours As Integer
Dim minutes As Integer

hours = CInt(Mid(Format(InNumber, "###0.00"), 1, Len(Format(InNumber, "###0.00")) - 3))

minutes = (InNumber * 100) Mod 100

minutes = minutes * 60 / 100

ConvertToTime = CStr(hours) & " Hours " & CStr(minutes) & " Minutes"
End Function


call it like so:

Me.txtTimeOut = ConvertToTime(CDbl(Me.txtTimeIn))
 
Don't know if there is an "official" way to do it but, you could create a function that takes in the two times.

Within the function:
1. Determine the difference in minutes. (DateDiff())

2. Divide this by 60.

3. Move the result of Step 2 (eg.10.75) to a text variable.

3. Take the Left(Variable,Len(variable)-3) of this text variable. (Should be 10)

4. Take the Mod of the division of the difference in minutes by 60. The Mod function gives the "remainder" of a division. Since the division is by 60, it gives the number of 60ths of an hour, ie minutes.

5. Concatinate the two with a colin between them and set the function equal to that.


 
Hi

Some options a little easier (& with ref to MichaelRed):

If the period is always less than one day, use:
= format(LaterTime - EarlierTime,"hh:mm")

If the period can be mulitple days, use
= DateDiff("d",EarlierTime,LaterTime) & " Days, " & format(LaterTime - EarlierTime,"hh:mm")

These can be used directly in the properties of the contol on your form or report.

Cheers

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top