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)
 Difference between two dates

Author  Topic 

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-08 : 09:28:24
Hi

I have two dates columns in 2 different tables
table1
regid
regdate

table2
regid
logindate

how to take the difference between these two dates,and find the average, in a stored procedure?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-08 : 09:32:32
Difference in what terms? day, month, year?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-08 : 09:32:42
[code]
select avg(abs(datediff(hour, t1.regdate, t2.regdate)) / 24.0) as [avg in days]
from table1 t1 inner join table2 t2
on t1.regid = t2.regid
[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-08 : 09:48:51
[code]declare @d1 datetime,
@d2 datetime

select @d1 = '19690906',
@d2 = '19760608'

select DATEADD(day, DATEDIFF(day, @d1, @d2) / 2, @d1),
DATEADD(day, DATEDIFF(day, @d2, @d1) / 2, @d2)[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-08 : 10:29:52
Thanks Everyone

I will try to use these statements in my SP
Go to Top of Page
   

- Advertisement -