Friday, March 8, 2013

If you wish to select the Date of the first Day of This Week, simply use the following:
SELECT CAST(DATEDIFF(DAY, 0, DATEADD(DAY, 1- DATEPART(DW, @InputDate), @InputDate)) AS datetime) AS OutputDate
Similarly, if you wish to select the Date of the last Day of This Week, use the following:
SELECT CAST(DATEDIFF(DAY, 0, DATEADD(DAY, 7- DATEPART(DW, @InputDate), @InputDate)) AS datetime) AS OutputDate

No comments: