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
 Format the difference in two dates as an interger

Author  Topic 

cwildeman
Starting Member

40 Posts

Posted - 2010-10-28 : 13:05:04
Hi,
I have a calculated field which subtracts two dates (See SQL statement below). Right now it returns a date such as 1901-02-15 00:00:00.000. I want it to simply return an interger such as 44. Can someone help me format this correctly?

dbo.vReadmit30Days2.AdmitDate2 - dbo.vReadmit30Days2.DischargeDate AS ReadmitDays

Thanks,
Chuck

Chuck W

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-28 : 13:09:12
[code]
DECLARE @d1 datetime; SET @d1 = '1/1/2010'
DECLARE @d2 datetime; SET @d2 = '2/14/2010'
SELECT DATEDIFF(dd,@d1,@d2)


[/code]


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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

cwildeman
Starting Member

40 Posts

Posted - 2010-10-28 : 14:02:36
Brett, Thanks for your help. I am new to this forum and to SQL Server (this is my second post). I did research the question before hand but could not come up with an answer. Was there something lacking in my question? I could have posted the entire SQL Statement but it was pretty massive. Chuck

Chuck W
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-01 : 07:17:43
quote:
Originally posted by X002548


DECLARE @d1 datetime; SET @d1 = '1/1/2010'
DECLARE @d2 datetime; SET @d2 = '2/14/2010'
SELECT DATEDIFF(dd,@d1,@d2)





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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx








Dont use local date formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

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

- Advertisement -