Link to home
Start Free TrialLog in
Avatar of Toti
Toti

asked on

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

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
Avatar of Tyip
Tyip

declare @i int

select  @i = 1234

select  convert( char(8), dateadd( ss, @i, '00:00:00' ), 108 )
ASKER CERTIFIED SOLUTION
Avatar of Tyip
Tyip

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Toti

ASKER

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