Solved

Change duration in seconds into hh:mm:ss format

Posted on 2004-03-26
5
542 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
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

809 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