Solved

Convert Seconds to hh:mm:ss

Posted on 2004-04-20
8
1,832 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
  • 4
  • 2
  • 2
8 Comments
 
LVL 35

Expert Comment

by:mrichmon
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 35

Accepted Solution

by:
mrichmon earned 50 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 15

Expert Comment

by:tim_cs
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No problem.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now