Hi @Sam332
Each week starts at Sunday and ends on Saturday
The first day of the week is based on your language settings of the server. The default setting for us_english is 7 (Sunday)
You can find the current first day of the week by using SELECT @@DATEFIRST
You could set Sunday to the first day of the week for the current connection by this SET DATEFIRST 7
How can I create another column that will create a weekly bucket based on the DateCreated column
You could use Datediff function, try this query:
Declare @Sample Table(UserName varchar(20), DateCreated date);
Insert @Sample(UserName, DateCreated) Values
('User1', '11/13/2022'),
('User2', '11/10/2022'),
('User3', '11/6/2022'),
('User4', '11/1/2022'),
('User5', '10/28/2021');
Select UserName,
DateCreated,
Datediff(wk,DateCreated,Getdate()) + 1 As WeeksAgo
From @Sample;
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.