'Why SQL datepart(ww,GETDATE()) returns current week + 1

I am trying to get current week of the calendar. Let's assume today is 2022-03-14 12:00:00.

I am using these 2:

select GETDATE() // returns 2022-03-14 12:00:00
select datepart(ww,GETDATE() //returns 12

But as per calendar 2022-03-14 12:00:00 should be 11st week.

From where is the difference coming from and how I can get basically current week?



Solution 1:[1]

GetDatePart(ww, ...) in SQL server is dependent on the set datefirst as documented here. You can use GetDatePart(isoww, getdate()) instead to get ISO Week Number.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cetin Basoz