# Thread: Converting integer to time

1. ## Converting integer to time

I have an INTEGER value (e.g. 174). I would like to display it in a TIME format (hh.nn.ss).

I have made a number of attempts and have been unsuccessful. I am guessing there is an easy way that I have missed.

2. ## Re: Converting integer to time

What does the integer value represent? Is it 174 seconds? You can't directly convert an INTEGER to a TIME, so you will probably have to write a small function to do it.

Brendan

3. ## Re: Converting integer to time

Yes seconds. It seemed that with all the datetime functions and conversions they have... there is something there to convert INTEGER seconds to a TIME format...

4. ## Re: Converting integer to time

I'm pretty sure none of the built-in TIME or DATETIME related functions will convert seconds to time. However its fairly straight-forward to do anyway.

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[-] testcase SecondsToTime() appstate none
[ ]
[ ] INTEGER s = 486 // 1 hour, 2 minutes, 6 seconds
[ ] INTEGER min, sec, hour
[ ]
[ ] // there are 360 seconds in an hour
[ ] hour = s/360
[ ] s = s%360
[ ]
[ ] // there are 60 seconds in a minute
[ ] min = s/60
[ ] s = s%60
[ ]
[ ] // whatever is left is the remaining seconds
[ ] sec = s
[ ]
[ ] print(&quot;hours: {hour}&quot
[ ] print(&quot;minutes: {min}&quot
[ ] print(&quot;seconds: {sec}&quot
[ ] </pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Of course you may want to take the results and create a TIME object but this gives you the main idea. If the code doesn't make sense let me know and I'll explain it. Hope that helps,

Brendan

5. ## Re: Converting integer to time

Actually, there are 3600 seconds in an hour.

6. ## Re: Converting integer to time

oops, yeah 3600 [img]images/icons/smile.gif[/img] thanks!

7. ## Re: Converting integer to time

Atention to detail

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.