Convert time into decimal format

superhorse

Registered User.
Local time
Today, 16:04
Joined
Apr 14, 2008
Messages
13
Does anyone know any simple code for converting a certain time period to a decimal?

In my form I have a field that displays the time a task took in short time (e.g. 2 hours is displayed as 02:00) and I want some code that can convert whatever value is put into that field into a decimal to then be more easily used in calculations.

The cost field will multiply this converted decimal by a rate depending on which client is selected from the client table.
 
You should be able to convert a Time into decimal format if you remember that time is stored as a decimal fraction of 24 hours. It is not clear how you want the figure to be displayed. Is it in hours and fractions of an hour so that 2:30 would be displayed as 2.5.

If this is the case then you just need to multiply the time by 24 and store the result as a decimal number. Hope this helps
 
You are right about the format I want, but rather than display the result I want to multiply the decimal by a [rate] field to find out different costs but it was the first part I was struggling with, thanks for your help.
 
I have an opposite question. I am doing a clockin/clockout for my work and when i run the difference in times such as TimeIn: 10:30AM TimeOut: 06:30PM. I am running a field in a query where its syntax is Hours: DateDiff("h",[TimeIn],[TimeOut]). I know the "h" displays hours but i don' know the function to display 8.5 as a return value
 
This will show the difference in decimal hours to x places.
Round(([TimeOut]-[TimeIn])*24,x)

BTW
Best to start a new thread with new questions as those with answers are less obviously in need of attention.
Welcome to Access programmers.
 
Just posted this on a similar thread
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
 
Does anyone know any simple code for converting a certain time period to a decimal?

In my form I have a field that displays the time a task took in short time (e.g. 2 hours is displayed as 02:00) and I want some code that can convert whatever value is put into that field into a decimal to then be more easily used in calculations.

The cost field will multiply this converted decimal by a rate depending on which client is selected from the client table.

This is what you are probably looking for:

DecTime = Lhour + Lminute / 60

where Lhour, Lminute are integers from the respective portions of the Time field or variable.

Best,
Jiri
 
Last edited:
Solo712,

Just wondering if you realized Superhorse's post is almost 5 years old. The response by David Crake, last in the thread, was 3 years old. Also, just for info
David passed away about a year ago.
 
Solo712,

Just wondering if you realized Superhorse's post is almost 5 years old. The response by David Crake, last in the thread, was 3 years old. Also, just for info
David passed away about a year ago.

Thanks, jdraw. I placed my response in the thread via link by mistake.

Best,
Jiri
 

Users who are viewing this thread

Back
Top Bottom