Solved

Change duration in seconds into hh:mm:ss format

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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

12 Experts available now in Live!

Get 1:1 Help Now