0

I need to add a column to show the week number of the year in my procedure.

By default the SQL Server considers the week starts as Sunday and shows the week number.

But I need to calculate the week number starts from Saturday.

Code:

select datepart(week,'11-july-2020') 

Output I get:

 28

Output I need:

 29

It should start considering from the week starts as Saturday and ends on Friday.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Thiyagu
  • 1,260
  • 1
  • 5
  • 14

1 Answers1

1

You can use DATEFIRST:

SET DATEFIRST 6;

select datepart(week,'11-july-2020'); 

It allows you to set the first day of the week to a number from 1 through 7, where 1 is Monday and 7 is Sunday.

gotqn
  • 42,737
  • 46
  • 157
  • 243