# Converting decimal time to hours:minutes:seconds

Any one know of a Crystal Reports formula that would convert decimal time into hours:minutes:seconds?

I know if I have 13.27 hours that I can do .27 x 60 = 16.2 minutes and take .2 x 60 = 12 seconds which would be 13:16:12  but not sure exactly how to make a formula in crystal reports.
LVL 1
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ERP System ManagerCommented:
Can't type out and test code as I'm on my phone, but the last comment on this post seems like it should do what you ask.

Commented:
Try this

``````Local NumberVar HoursInSeconds;
Local NumberVar Minutes;
Local NumberVar Hours;

HoursInSeconds := {YourDecimalTime} * 3600;
Hours := HoursInSeconds  / 60;
HoursInSeconds  := HoursInSeconds  MOD 60;
Minutes := HoursInSeconds  / 60;
HoursInSeconds  := HoursInSeconds  MOD 60;

CStr(Hours,0,'') & ":" & CStr(Minutes,0,''), & ":" & CStr(HoursInSeconds ,0,'')
``````

mlmcc
Commented:
If the number will always be less than 24 (and positive), like a time of day, you can just use:

But if it's something like an elapsed time and it can be 24 hours or more, or it can be negative, then you need something more complicated, like the formula that mlmcc posted.  Here's another way to handle those larger values.  It converts the whole hours to a string, then uses the Time and CStr functions to convert the decimal places to minutes and seconds.

CStr (Truncate ({your field}), "#") + ":" +

If the value could be negative, you'd need to add something to handle that.

James
IT ManagerAuthor Commented:
I won't have a negative.

mlmcc

I tried your formula but it's giving me 8:0:24 for .14 hours worked when it should be 0:8:24.

It didn't like the comma in line 11 so I had to remove it.
IT ManagerAuthor Commented:
markusdamenous

I tried this and it gives me an error of " The remaining text does not appear to be part of the formula.
IT ManagerAuthor Commented:
Actually now they tell me that they only want the decimal time to be converted to minutes and then I'll need to divide the quantity made by the minutes to get the time per unit.
Commented:
Just multiply your decimal time field by 60

mlmcc
Commented:
Corrected formula from above

``````Local NumberVar HoursInSeconds;
Local NumberVar Minutes;
Local NumberVar Hours;

HoursInSeconds := 0.14 * 3600;
Hours := HoursInSeconds  / 3600;
HoursInSeconds  := HoursInSeconds  MOD 3600;
Minutes := HoursInSeconds  / 60;
HoursInSeconds  := HoursInSeconds  MOD 60;
``````

mlmcc

Experts Exchange Solution brought to you by