?
Solved

How to convert seconds to hh:mm:ss in a sql query

Posted on 2003-02-27
3
Medium Priority
?
2,216 Views
Last Modified: 2006-11-17
Hi.

I'm new to this but can anyone help me with how to convert seconds to hours:minutes:seconds in a sql query.

My query is like this:

"select duration from tablename"

The column duration returns seconds and I want to format it in to hh:mm:ss in the statement.

Thanks.
Toti
0
Comment
Question by:Toti
[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
  • 2
3 Comments
 

Expert Comment

by:Tyip
ID: 8034450
declare @i int

select  @i = 1234

select  convert( char(8), dateadd( ss, @i, '00:00:00' ), 108 )
0
 

Accepted Solution

by:
Tyip earned 200 total points
ID: 8034465
in your case, it will be

select convert( char(8), dateadd( ss, duraction, '00:00:00' ), 108 )
from tablename
0
 

Author Comment

by:Toti
ID: 8180505
Excellent answer and does the job.  

However if I want to add number of days in front of hours so the display would be like this dd:hh:mm:ss or for that matter yy:mm:dd:hh:mm:ss.  What would that sql script look like?

The thing is that I'm using this script on Call Detail Records in a Phone System for a summation of call time.  In a year period total talk time would be measured in the above scale.

Regards Toti
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

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