I have a query where I am grouping by week using DatePart(ww , [TimeEntryDate]) for the column and it returns the week number. I would like to display the week ending date and like that to always be a saturday.
Here’s the complete query
SELECT
DatePart(year , [TimeEntryDate]) [YEAR],
DatePart(ww , [TimeEntryDate]) Week,
CategoryId,
SUM(TimeEntryDuration) "Total Hours"
FROM [TIMETRACKER].[dbo].[aspnet_starterkits_TimeEntry]
GROUP BY DatePart(year , [TimeEntryDate]), DatePart(ww , [TimeEntryDate]) , CategoryId
ORDER BY 1,2,3
data
Year Week Category Total Hours
2010 1 1 10
2010 2 1 12
You can try the following
EDIT: The settings for start date is based on your language settings. The U.S. English default is 7, Sunday, but you need to verify your settings and adjust the calculation accordingly. You can verify your settings to determine which day is the start of the week with
This query will illustrate the difference:
You can also set your week start date as follows.