Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading