SQL Server default Sunday is the first day of the week and thus has the following output:
Program Code
1 Print DatePart(DW,'2013-01-05')--7, Saturday2 Print DatePart(WK,'2013-01-05')--1, first week3 Print DatePart(DW,'2013-01-06')--1, Sunday4 Print DatePart(WK,'2013-01-06')--2, second week, week one
This does not fit our habit, fortunately SQL Server provides set DATEFIRST let's set the first day of the week to a few weeks.
SQL Server Settings Monday is the first day of the week
Program Code
1 SETDatefirst12 Print DatePart(DW,'2013-01-05')--6, Saturday3 Print DatePart(WK,'2013-01-05')--1, first week4 Print DatePart(DW,'2013-01-06')--7, Sunday5 Print DatePart(WK,'2013-01-06')--1, first week
Description: The default value for set datefirst in SQL Server is 7, and the current value can be viewed by performing a SELECT @ @DATEFIRST.
MSSQL set the first day of the week