MSSQL set the first day of the week

Source: Internet
Author: User
Tags mssql

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.