Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Seconds

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-10 : 15:59:44
I am really confused and I can’t concentrate. Please help me with this easy question:
I have a field which contains seconds for example 128460 I need to have how much hours is that in my Query.
Please Help me.


Sep

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-10 : 16:06:57
Divide by 3600, since there are 3600 seconds in every hour.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-10 : 16:09:03
I know that but I need to have 35 hours and 41 minutes like this 35.41.
Please help me.
Sep
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-06-10 : 16:33:55
I tried it myself and here it is
declare @S as bigint
set @S=128460


Select @s/3600
Select (@s % 3600)/60

Sep
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-10 : 16:34:13
[code]DECLARE @Seconds INT

SET @Seconds = 128460

SELECT CAST(@Seconds / 3600 AS VARCHAR(12))
+ '.'
+ STUFF(RIGHT(CONVERT(VARCHAR(8), DATEADD(SECOND, @Seconds, '00:00'), 108), 5), 3, 1, '.')[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-10 : 16:37:37
select datediff(hour,0,dateadd(second,128460,0)),datediff(minute,0,dateadd(second,128460,0))%60


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-06-10 : 16:53:57
[code]
select
Hours_Minutes = datediff(hh,0,DT)+(datepart(mi,DT)*.01)
from
(select DT = dateadd(ss,128460,0) ) a



Results:

Hours_Minutes
----------------
35.41

(1 row(s) affected)


[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -