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
lrollinsIT ManagerAsked:
Who is Participating?
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.

Mark DamenERP 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.

http://www.tek-tips.com/viewthread.cfm?qid=1685015
0
mlmccCommented:
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,'')

Open in new window


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

Time ({your field} / 24)

 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}), "#") + ":" +
 CStr (Time (({your field} - Truncate ({your field})) / 24), "mm:ss")

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

 James
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

lrollinsIT 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.
0
lrollinsIT 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.
0
lrollinsIT 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.
0
mlmccCommented:
Just multiply your decimal time field by 60

mlmcc
0
mlmccCommented:
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;

Open in new window


mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lrollinsIT ManagerAuthor Commented:
That worked.  Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.