To be able to use any date, and based on that date, get the start (Sunday) and end (Saturday) dates, use the following T-SQL:
Start of Week (sunday): DATEADD(wk, DATEDIFF(wk, 6, @mydt), 6)
End of week (saturday): DATEADD(wk, DATEDIFF(wk, 5, @mydt), 5)
To test it, just add the following to a new sql query in SQL Server:
Declare @mydt DateTime Set @mydt='8/4/2010' Select DATEADD(wk, DATEDIFF(wk, 6, @mydt), 6) as StartDate, DATEADD(wk, DATEDIFF(wk, 5, @mydt), 5) as EndDate
All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF
Leave a reply
You must be logged in to post a comment.