How to get a date of day in current week

Spunny 326 Reputation points
2024-10-02T17:24:40.53+00:00

Hi,

I have table that stores configurations like

User's image

In my sql code, I need to take currentDateTime and get

  1. current week date for Execution Day which is Wednesday. So, for this week, it will be 10-02-2024.
  2. Get following week wednesday date. Here it will be 10-09-2024
  3. Get CutOffDate for that current week cutoffday (which is Friday). So, for this week it will be 10-04-2024
  4. Then I need to see if currentdatetime (now) is less than cutoffdatetime (10-04-2024 17:00:00) if it is less than, then I should get
                 Following Wednesday as nextexecution date should be following wednesday(10/09/2024)
       ```1. If currentdatetime > cuttoffdatetime (10-04-2024 17:00:00), for example currentdateTime is 10-04-2024 18:30:00) Then nextexecutiondate should be 2 weeks wednesday which is 10-16-2024.
    
    

Our sever is set up default to Sunday as start of the week.

How do I achieve this.

TIA.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,770 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.