Solved

Convert Seconds to hh:mm:ss

Posted on 2004-04-20
8
1,926 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
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. …

688 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