Solved

Change duration in seconds into hh:mm:ss format

Posted on 2004-03-26
5
543 Views
Last Modified: 2008-07-03
Hi there,

I have a table A with column duration (int) and I would like to view the duration (initially in seconds) in hh:mm:ss format.

Example,

Table A
---------
duration       Expression1
120             00:02:00
110             00:01:50
45               00:00:45
3602           01:00:02

What is the sql statement to convert the seconds into the mentioned format (hh:mm:ss)?


:O)
0
Comment
Question by:allicia
[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
  • 3
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 10685280
select convert(char(8),dateadd(s,duration,'19000101'),108)

so add the duration to 1st jan 1900
then convert it back to character using format 108 which is just time....

should work as long as duration is less than 24hours...

0
 
LVL 26

Accepted Solution

by:
Hilaire earned 80 total points
ID: 10685294
select convert(varchar, dateadd(s, duration, 0), 108) from tableA
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10685300
Oops,
Sorry Lowfatspread for duplicate post
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10685342
@allicia,
Lowfatspread was the first to come with the solution,
mine is exactly the same although the syntax slightly differs
'19000101' is the 'root' date and is stored internally as 0
I feel miserable for getting the points that LFS deserved

@LFS
my apologies again

@both
I'm OK for the points to be reaffected
Or I can post a "points for LFS" question

Thks

Hilaire
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 10685348
no problem  hilaire
;-)

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

756 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