Decimal number to hours

R

Rishi

How do I calculate a decimal to hour:min:sec?

e.g. I want to calculate 157.369 to 157:22:08.

I tried [decnr]/24 but that works only if [decnr]<24. The format of the
calculated field is h:nn

I think this is a simple problem, but for some reason I don't get the result
I want.
 
S

Stefan Hoffmann

hi Rishi,
How do I calculate a decimal to hour:min:sec?

e.g. I want to calculate 157.369 to 157:22:08.

I tried [decnr]/24 but that works only if [decnr]<24. The format of the
calculated field is h:nn
Imho this, untested:

Public Function DecimalToTimeStr(AValue As Double) As String

Dim Rest As Double

Dim Hours As Integer
Dim Minutes As Integer
Dim Seconds As Integer

Hours = Int(AValue)
Rest = AValue - Hours

Minutes = Int(Rest / (1 / 60))
Rest = Rest - Minutes * (1 / 60)

Seconds = Rest / (1 / 60 ^ 2)

DecimalToTimeStr = Hours & ":" & Minutes & ":" & Seconds

End Function


mfG
--> stefan <--
 
R

Rishi

Thnx Stefan!
this is what I wanted

I'm learning every day :)

Stefan Hoffmann said:
hi Rishi,
How do I calculate a decimal to hour:min:sec?

e.g. I want to calculate 157.369 to 157:22:08.

I tried [decnr]/24 but that works only if [decnr]<24. The format of the
calculated field is h:nn
Imho this, untested:

Public Function DecimalToTimeStr(AValue As Double) As String

Dim Rest As Double

Dim Hours As Integer
Dim Minutes As Integer
Dim Seconds As Integer

Hours = Int(AValue)
Rest = AValue - Hours

Minutes = Int(Rest / (1 / 60))
Rest = Rest - Minutes * (1 / 60)

Seconds = Rest / (1 / 60 ^ 2)

DecimalToTimeStr = Hours & ":" & Minutes & ":" & Seconds

End Function


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top