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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 count hours

Author  Topic 

PatDeV
Posting Yak Master

197 Posts

Posted - 2006-09-20 : 11:37:30
Hi all,

how can i count hours between two time

help plz!!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-20 : 11:40:35
assuming the two times are datetime datatyps:

select datediff(hour, datetimeCol1, datetimeCol2)

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-20 : 11:41:52



DECLARE @s datetime, @e datetime
SELECT @s = '10/24/1960', @e = Getdate()
SELECT DATEDIFF(hh,@s,@e)



Man that's a lot of hours



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-20 : 11:44:40
>>SELECT @s = '10/24/1960'

Is that your birthday, old man?

Be One with the Optimizer
TG

EDIT:

that's ok, if it is I'm still this many hour older than you: 13512
Go to Top of Page

PatDeV
Posting Yak Master

197 Posts

Posted - 2006-09-20 : 13:59:39
but the time is in seconds????:(
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-20 : 14:30:38
>>but the time is in seconds????:(
huh?

What is the datatype of your "time" values?
Can you provide an example of what you have and what you want?

You do know that you can convert seconds to hours by deviding by 3600.0, right?


Be One with the Optimizer
TG
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 02:32:47
Algebra 101.

SELECT (ToSecondsColumn - FromSecondsColumn) / 3600.0 DiffInHours
FROM MyTable

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-21 : 09:14:20
Good Lord


DECLARE @s datetime, @e datetime
SELECT @s = '10/24/1960', @e = Getdate()
SELECT DATEDIFF(ss,@s,@e)



Do you know what Books Online is? You need too.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -