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
 Datediff

Author  Topic 

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-06-24 : 11:23:53
Hi there i am using the datediff funtion but it does not seem to be inclusive of the two dates eg
SELECT DATEDIFF(day, s_Date, e_date) AS NumberOfDays,*
FROM weekendtest

i know i could do
SELECT DATEDIFF(day, s_Date, e_date)+1 AS NumberOfDays,*
FROM weekendtest

but i was just wondering if there some other function i should use that would be more appropriate

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-06-24 : 11:28:47
Not really . . well if you don't like to + 1, you can use - 1

SELECT DATEDIFF(day, s_Date - 1, e_date) AS NumberOfDays
FROM weekendtest



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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-24 : 13:05:19
Datediff would exclude the first parameter date from counting

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-24 : 13:44:14
Here is an article of how DATEDIFF works.
http://www.sqlteam.com/article/datediff-function-demystified



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -