Solved

Convert Seconds to hh:mm:ss

Posted on 2004-04-20
8
1,901 Views
Last Modified: 2013-12-20
If I  have an amount of time stored as seconds in my Access dbase and I want to convert the seconds to reflect hh:mm:ss format on ColdFusion page, how is that easily done?

If I have 23400 seconds and I know that this would be 6 hours and 30 minutes, how do I get it to appear on my page as 06:30:00?
0
Comment
Question by:Lee R Liddick Jr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 10870297
You can do the division.

<cfset myseconds = 23400>
<cfset hrs = myseconds / 3600>
<cfset min = (myseconds mod 3600) / 60>
<cfset sec = (myseconds mod 3600) mod 60>

<cfoutput>
#hrs#:#min#:#sec#
</cfoutput>

And use NumberFormat if you want to force to be 2 digits
0
 

Author Comment

by:Lee R Liddick Jr
ID: 10870377
My hours are giving me 6.5...so in the above example, it's showing 6.5:30:00 on the page...
0
 
LVL 15

Assisted Solution

by:tim_cs
tim_cs earned 25 total points
ID: 10870412
mrichmon has the right idea but you should add SpanExcluding so things like 6.5 won't show up for hours

<cfset myseconds = 23400>
<cfset hrs =  SpanExcluding(myseconds / 3600, ".")>
<cfset min =  SpanExcluding((myseconds mod 3600) / 60, ".")>
<cfset sec =  SpanExcluding((myseconds mod 3600) mod 60, ".")>
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 35

Accepted Solution

by:
mrichmon earned 50 total points
ID: 10870445
Actually you need Fix which forces integer divisioninstead of float division :

<cfset myseconds = 23400>
<cfset hrs = Fix(myseconds / 3600)>
<cfset min = Fix((myseconds mod 3600) / 60)>
<cfset sec = (myseconds mod 3600) mod 60>

Fix takes the closest integer below the float.  SO 1.5 returns 1 and 2.4 returns 2 and 4.99999 returns 4
0
 
LVL 15

Expert Comment

by:tim_cs
ID: 10870453
You could also use the following to get the correct format. The above would give a time like 6:30:5 for 23405 but this should fix that.

<cfoutput>
#TimeFormat(createTime(hrs,min,sec), 'H:M:SS')#
</cfoutput>
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10870454
Note you do not need to use Fix for modular division, just for the ones where you want integer division i.e. the /
0
 

Author Comment

by:Lee R Liddick Jr
ID: 10870564
Thanks to you both!  I had to give the majority of the points to mrichmon since he answered first and I had to give him time to respond to my second question, but your solution would have worked as well tim_cs so I increased the point total and sorted out the points to both of you!  I love this place!!!  You guys are great!  I'm having to build a web application at work with no training whatsoever in ColdFusion and everything I have learned I have learned from my SAMS book and you guys on this site...it is very much appreciated!!!
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10870607
No problem.
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question