Solved

Convert to hh:mm:ss

Posted on 2011-02-15
4
1,144 Views
Last Modified: 2012-05-11
This is SQL 2000.

I have a value that's in seconds (now it could be milliseconds but since i cant see the code, i'm not sure which). I think it's millisecond...

I have below and it converts the value to 00:20:10 but i think it should be 24:20:10..that's why i think the value is actually in milliseconds..not seconds...how can I fix this (convert mlillisecond to hh:mm:ss?)
declare @test as int
set @test = 87610 -- i think this is millisecond but the output should be 24:20:10 NOT 00:20:10
select convert(varchar(8),dateadd(ss,isnull((@test),0),'00:00:00'),108) Avg_Response_Time

Open in new window

0
Comment
Question by:Camillia
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 34900509
Can you check this?

declare @test int
set @test = 87610
select case when @test/3600 < 10 then '0' + convert(varchar(10),@test/3600) else convert(varchar(10),@test/3600) end + ':' +
       case when (@test%3600)/60 < 10 then '0' + convert(varchar(10),(@test%3600)/60) else convert(varchar(10),(@test%3600)/60) end + ':' +
       case when @test%60 < 10 then '0' + convert(varchar(10),@test%60) else convert(varchar(10),@test%60) end
-- 24:20:10

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 34900526
yes, that worked. Whats missing from mine? just totally wrong or just gets the seconds?
0
 
LVL 40

Expert Comment

by:Sharath
ID: 34900617
in the format HH:MI:SS, the hours cannot exceed 24. At max the value would be 23:59:59 and after that the day will be increment to one resetting the HH:MI:SS to start from 00:00:00 for next day.
In your case 24:20:10 won;t be displayed instead the day would be incremented and time part would be displayed as 00:20:10

Run this and see the day got changed to 02.

declare @test as int
set @test = 87610 -- i think this is millisecond but the output should be 24:20:10 NOT 00:20:10
select convert(varchar(50),dateadd(SECOND,isnull((@test),0),'00:00:00'),120) Avg_Response_Time
-- 1900-01-02 00:20:10

Open in new window


0
 
LVL 7

Author Comment

by:Camillia
ID: 34900627
thanks, i have a related question and i will open a new question.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

815 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