If I want to make sure an operation can only be done once a week by a user, what is an efficient way to do it? If a user has carried out that operation on Friday, then he can still do it on Tuesday, because it’s “next” week.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Create a table that stores a history of user actions:
To check if the user has performed an action during the same week, you can use the DATEPART function to determine the week:
IF EXISTS (SELECT * FROM UserActions WHERE userId = @userID and weekOfYear = DATEPART(isowk, GetDate() AND year = Year(GetDate())If that returns NULL, the user hasn’t performed any actions in the current week. Then, you could insert a row after the action is performed.