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 2005 Forums
 Transact-SQL (2005)
 Datetime variables - difference in days

Author  Topic 

agniwoni
Starting Member

28 Posts

Posted - 2007-07-06 : 11:41:21
I have 2 datetime type variables, and I want sql server to tell me how many days they differ.

D1 = 2007-06-01
D2 = 2007-06-15
result of D2-D1 should be 14 days

Thanks in advance for any help!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-07-06 : 11:46:07
Did you take any efforts to go through SQL Server help at all?

select Datediff(day, @d1, @d2) as Days


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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-06 : 22:15:42
here is it from BOL
http://msdn2.microsoft.com/en-us/library/ms189794.aspx


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

Go to Top of Page
   

- Advertisement -