Anyone have a better idea than this?
I am considering Sunday the week-ending date.
Results:
[tt]dt weekendingdate
2004/07/05 2004/07/11
2004/07/06 2004/07/11
2004/07/07 2004/07/11
2004/07/08 2004/07/11
2004/07/09 2004/07/11
2004/07/10 2004/07/11
2004/07/11 2004/07/11
2004/07/12 2004/07/18
2004/07/13 2004/07/18
2004/07/14 2004/07/18
2004/07/15 2004/07/18
2004/07/16 2004/07/18
2004/07/17 2004/07/18[/tt]
Code:
-- where dt is a date column,
SELECT weekendingdate = convert(datetime,convert(int,floor(convert(bigint,convert(varbinary,dt)) / 4294967296)) / 7 * 7 +6)
FROM Table
I am considering Sunday the week-ending date.
Results:
[tt]dt weekendingdate
2004/07/05 2004/07/11
2004/07/06 2004/07/11
2004/07/07 2004/07/11
2004/07/08 2004/07/11
2004/07/09 2004/07/11
2004/07/10 2004/07/11
2004/07/11 2004/07/11
2004/07/12 2004/07/18
2004/07/13 2004/07/18
2004/07/14 2004/07/18
2004/07/15 2004/07/18
2004/07/16 2004/07/18
2004/07/17 2004/07/18[/tt]