Time to decimal conversion

Keith166

Registered User.
Local time
Tomorrow, 01:19
Joined
Nov 4, 2007
Messages
43
I'm a novice needing to convert a short time value to a decimal so that a calculation of Time X Rate of Pay can be made. I've tried the following Microsoft code after resetting the format to short time but I still get a short time result.

Public Function timetodec(Time1)
timetodec = CDbl(Time1) * 24
End Function

I'm stuck! please help
 
Try adding "As Double" to the Function statement like this:
Code:
Public Function timetodec(Time1) As Double
timetodec = CDbl(Time1) * 24
End Function
 
Short Time Conversion

Nope! still getting a SHORT TIME????
 
Would you type this into the immediate window, then copy the results and put those results into your reply.

?timetodec(#6:30:00#)

Thanks,
 
You need to convert yout short time to a value that will enable your calculation to be carried out.

You need the following formulae 06:30 [your short time] * 1440/60 will give you 6.50 [decimal]

Clearly the 1440 and 60 values will need to be constants in setting up your various variables to perform this conversion.

I trust this helps

John
 
The field that I'm trying to convert to decimal has been produced by the following code:

Function GetElapsedTime(interval)
Dim totalhours As Long, totalminutes As Long
Dim Hrs As Long, Min As Long
totalhours = Int(Nz(CSng(interval * 24)))
totalminutes = Int(Nz(CSng(interval * 1440)))
Hrs = totalhours Mod 24
Min = totalminutes Mod 60
GetElapsedTime = Hrs & " Hrs " & Min & _
" Min "
End Function

I really appreciate your interest in my problem...thanks!
 
Hi,

Where is the totalhours and totalminutess getting their values from? I'm by no means an expert, but have done some coding converting time values to decimal, but not seen the code block you sent before. So I'm not sure what that code is doing entirely.


Sorry.

John
 
I downloaded the code from microsoft and use it to calculate StartTime minus EndTime and show just hours and minutes.
 
Hi,

This looks a long way to achieve what your looking for, a formulae I have used subtracts the start time from the end time [assuming that the start time is earlier than the end time] to calculate the time difference in hours and minutes, I then use the formulae 1440/60 to obtain the total time in hours and minutes in decimal i.e 10:06 substracted from 10:34 = 27:56 minutes * 1440/60 = 0.47

I hope this helps.

John
 
John,
Thanks for setting me straight - works just fine. Got of the track a bit there didn't I.
Regards
Keith
 

Users who are viewing this thread

Back
Top Bottom