?
Solved

Convert Seconds to hh:mm:ss

Posted on 2004-04-20
8
Medium Priority
?
1,967 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 100 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
Limited time offer using promo code EXPERTS25

Designed with a wealth of functionality and convenience, ATEN's new Thunderbolt™ 2 Sharing Switch takes your Thunderbolt setup to the next level. Now through August 31, 2017, Experts Exchange members get 25% off the US7220 on the ATEN USA eShop using promo code EXPERTS25.

 
LVL 35

Accepted Solution

by:
mrichmon earned 200 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

801 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