Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I want to know how datediff function works.SET DATEFORMAT MDYset nocount ondeclare @from_date varchar(12), @to_date varchar(12)select @from_date = '06/01/2004'select @to_date = '06/12/2004'SELECT DATEDIFF(wk, @from_date, @to_date)it calculates one weeks while there are more than 7 days. Why it is behaving like this?
RickD
Slow But Sure Yak Herding Master
3608 Posts
Posted - 2004-06-28 : 07:54:53
because it only give full weeks as the return type is an int... If you want partial weeks, then find the amount of days and divide by 7...
ditch
Master Smack Fu Yak Hacker
1466 Posts
Posted - 2004-06-28 : 07:57:26
Yeah something like this:select cast(datediff(dd, '2004-06-01', '2004-06-12') as decimal(18, 2)) / 7 Duane.
Pat Phelan
Posting Yak Master
187 Posts
Posted - 2004-06-28 : 15:50:32
What DateDiff really counts is transitions. Since the first day of the week is normally Sunday, on my machine the following statement: