Reputation: 157
Why is the datediff for the week and day returning the same results for week and day?
This is the query I am using;
select DATEDIFF("D",[ARRS-DATE], GETDATE()) daysdiff ,DATEDIFF("W",[ARRS-DATE], GETDATE()) weeksdiff,* from [RE-ARRS-HIST]
Any ideas on what can be causing this?
Thanks in advance.
Upvotes: 0
Views: 46
Reputation: 69789
"w"
is not shorthand for weeks, it is an alias for WEEKDAY
. Since Weekday does not really make sense as a datediff option, I would guess that this is treated like days under the hood.
If you want weeks difference, you need to use "ww"
or "wk"
. Or better still use the full version WEEK
, it is much more clear, and is not much harder to write at all.
SELECT DATEDIFF(DAY, [ARRS-DATE], GETDATE()) AS daysdiff,
DATEDIFF(WEEK, [ARRS-DATE], GETDATE()) AS weeksdiff
FROM [RE-ARRS-HIST];
Bad Habits to Kick : Using shorthand with date/time operations
Upvotes: 5