January 24, 2014 at 3:16 am
What is the difference between
DATEDIFF(W,Date1,Date2)
and
DATEDIFF(D,Date1,Date2)
for example the below code return same results
select DATEDIFF(W,Getdate(),Getdate()+2)
select DATEDIFF(D,Getdate(),Getdate()+2)
Thank You in advance
Rabih
rkaram
January 24, 2014 at 3:24 am
Although not mentioned in the documentation, W stands for WeekDay. You can see this if you hover with your mouse over the W.
I guess that's probably the same as Day?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 24, 2014 at 3:30 am
as I understand,
"To calculate the number of days between date1 and date2, you can use either Day of year ("Y") or Day ("D"). When interval is Weekday ("W"), DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2 but not date1."
but here the result isnt the case
rkaram
January 24, 2014 at 3:47 am
It seems to me weekdays calculates days, not the number of Mondays.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 24, 2014 at 7:30 am
rabih_karam (1/24/2014)
as I understand,"To calculate the number of days between date1 and date2, you can use either Day of year ("Y") or Day ("D"). When interval is Weekday ("W"), DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2 but not date1."
but here the result isnt the case
That's from Access help. The SQL Server function is slightly different. Natch.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply