Converting Time into a decimal

Goingcrazy

Registered User.
Local time
Today, 13:25
Joined
May 5, 2008
Messages
23
Hi,
I have a database about Equipment maintenance, and I need to convert total time into a decimal. On a form i have Time In and Time Out fields and Total time =[TimeOut]-[TimeIn]. What I need to be able to do is get the total time calculation to display a decimal such as 1.5, instead of 1:32 in short time format. Does anyone have a simple solution to this?
Thanks
Sarah
:rolleyes:
 
Howzit

Time and date values are actually stored as a double data type - it is just the formatting that displays as time etc. Play with your formatting
 
I'm sorry Im kind of new to access. Could you possibly tell me how to create a custom format that might help with the conversion?
thanks
:rolleyes:
 
Howzit

In design view of your form, select the text box in question, rt click and select properties, select the format tab, type in standard - this will change the time format to a decimal
 
Thanks but that didnt really help. i have 1:32 in short format from the calculation and it shows up as 0.06 when i change it to standard. Maybe i wasnt clear on what i was trying to do. I need to have that change to 1.5 hours after it calculates the total time.
 
Howzit

To show your time in hours, should your formual be ([TimeOut]-[TimeIn])*24 or alternatively

DateDiff("h",[TimeOut],[TimeIn])
 
Thanks. I thought thats what i had been doing all day but maybe I had the wrong format. But its working great now. I really appreciate it.
 
Where would you place this formula to calculate the time and enter into the table? the only place i can get it to show up is the control source but then it doesn't get written to the table. Thanks
 
I have a similar problem. I am using the DateDiff function. The value is returning a decimal but not the decimal places. If someone worked 8 hrs and 30 minutes, i get 8.00 as the return value.Yes I've checked everything in the query to make sure the format is set to standard with the necessary amount of decimals.
 
Here is a simple function that turns a time into a fraction

Code:
Public Function TimeToFraction(Optional Anytime As String) As Double
If IsEmpty(Anytime) Then
    Anytime = "00:00:00"
End If

Dim H As Integer
Dim M As Double
H = IIf(Val(Left(Anytime, 2)) > 0, Val(Left(Anytime, 2)), 0)
If Val(Mid(Anytime, 4, 2)) > 0 Then
    M = Val(Mid(Anytime, 4, 2))
    M = ((M / 60) * 100) / 100
Else
    M = 0
End If
TimeToFraction = Round(H + M, 2)

End Function

David
 

Users who are viewing this thread

Back
Top Bottom