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
 Select query with days

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2009-12-30 : 05:33:28
Dear All,

I have a table structure like this..

EmpID | Fromdate
1 | 1985-10-31
2 | 1972-01-12
3 | 2000-12-08

By considering "2010-10-31" as a Reference date
I need to get the difference in days between Fromdate and Reference date .

Thanks,
Gangadhar

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-30 : 05:39:15

select DATEDIFF(d,Fromdate,'2010-10-31') from table_name

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-30 : 05:40:29
SELECT DATEDIFF(DAY,Fromdate,'2010-10-31')as Datedifft
FROM <Table>


You can use DATEDIFF in the select list, WHERE, HAVING, GROUP BY and ORDER BY clauses
-------------------------
R...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-02 : 01:45:41
is Fromdate datetime field? if not, will the date formats of values be consistent?
Go to Top of Page
   

- Advertisement -