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

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-06-29 : 10:17:03
How to find difference(in months) between the most recent and oldest order dates? ia a same column

Regard,Sg

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-06-29 : 10:19:43
SELECT DATEDIFF(month,Oldest,Newest)
FROM
( select min(orderdate) as Oldest,max(orderdate) as Newest from yourTable)
) t

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 11:11:44
or

select datediff(month,min(orderdate) ,max(orderdate)) from yourTable

Madhivanan

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

- Advertisement -