Using DATEPART to get a week

Source: Internet
Author: User

Take the date 2017-12-11 (Monday) as an example

one or one-like usage

Select DATEPART (Weekday, ' 2017-12-11 ')

Results: 2

Description: Due to MS SQL default Sunday is the 1th day of one weeks, so 2017-12-11 Monday on the 2nd day of one weeks. So analogy: 1. 7 represents the Sunday. Saturday


Ii. setting Monday as the 1th day of one weeks

Set Datefirst 1 -This sentence will be set in Monday for the 1th day of one weeks.

Select DATEPART (Weekday, ' 2017-12-11 ')

Results: 1

Description: Set Datefirst 1 can be set to Monday one weeks on the 1th day, so 2017-12-11 Monday on the 1th day of one weeks. So analogy: 1. 7 represents the Monday. Sunday.


three, the use of SET Datefirst

Syntax: SET datefirst {number | @number_var} 

Parameters
Number | @number_var
indicates an integer for the first day of the week. Can be one of the following values.

The first day of the week is &NBSP
1 week  
2 Tuesday  
3 week three  
4 week four  
5 Friday  
6 Saturday  < br> 7 Week day (default, U.S. English)
  
Description:  
To view the current settings of the set Datefirst, use the @ @DATEFIRST function. The settings for the

set Datefirst are set at execution or Run-time, not at parse time.


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.