Decimal number to hours

  • Thread starter Thread starter Rishi
  • Start date Start date
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.
 
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 <--
 
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 <--
 
Back
Top