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
 Date difference Query

Author  Topic 

rc1138
Starting Member

35 Posts

Posted - 2010-05-30 : 21:46:37
Hi all,

I'm trying to calculate the day difference between the current date and the last known update to a column. I might be going over this particular query the wrong way however

I have this table called irActivity and in it is a column called
irActDate

My query is as follows

SELECT COUN(DATEDIFF(DAY,irActDate,GETDATE())) AS DAYS
FROM irActivity


It produces this result

Days
6

But the last entry in my irActDate column is 1/1/1997 so there should be thousands of days as the difference between 1/1/1997 and todays date

*1/1/1997 is the last entry of the column so I'm thinking that part of the syntax may be wrong as well. By putting the name of the column in the condition will it automatically take the last entry ?

Thanks again !

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-30 : 21:59:36
quote:
SELECT COUNT(DATEDIFF(DAY,irActDate,GETDATE())) AS DAYS
FROM irActivity

You are counting the number of record in the table irActivity in the above query.

maybe you wanted this ?

select datediff(day, max(irActDate), getdate()) as DAYS
from irActivity



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rc1138
Starting Member

35 Posts

Posted - 2010-05-30 : 22:26:55
Thats exactly it thanks!
Go to Top of Page
   

- Advertisement -