I have the following which seems to work perfectly, except that it's always 1 less than the count I need:
DECLARE @start_day DATETIME;
DECLARE @end_day DATETIME;
DECLARE @start_time DATETIME;
DECLARE @end_time DATETIME;
SET @start_day = '2013-06-03';
SET @end_day = '2013-06-07';
PRINT DATEDIFF(d, @start_day, @end_day)
- DATEDIFF(wk, @start_day, @end_day) * 2
- CASE
WHEN DATEPART(dw, @start_day) != 7 AND DATEPART(dw, @end_day) = 7 THEN 1
WHEN DATEPART(dw, @start_day) = 7 AND DATEPART(dw, @end_day) != 7 THEN -1
ELSE 0
END
I should be getting
`5` for `2013-06-03` to `2013-06-07` but it's giving me `4`.
`5` for `2013-06-03` to `2013-06-08` but it's giving me `4`.
`5` for `2013-06-03` to `2013-06-09` but it's giving me `4`.
`6` for `2013-06-03` to `2013-06-10` but it's giving me `5`.
So my question is:
How do I get:
`2013-06-03` to `2013-06-07` to equal 5
`2013-06-03` to `2013-06-08` to equal 5
`2013-06-03` to `2013-06-09` to equal 5
`2013-06-03` to `2013-06-10` to equal 6
Please note, adding +1 to the end does not solve the problem!!!