Link to home
Start Free TrialLog in
Avatar of allicia
allicia

asked on

Change duration in seconds into hh:mm:ss format

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)
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

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...

ASKER CERTIFIED SOLUTION
Avatar of Hilaire
Hilaire
Flag of France image

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
Oops,
Sorry Lowfatspread for duplicate post
@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
no problem  hilaire
;-)