Calculates the 2nd day of the week on which the given date (Sunday is the first day) SQL statement

Source: Internet
Author: User

Calculates the 2nd day of the week on which the given date is located (Sunday is the first day)

DECLARE @date datetime
Set @date = GETDATE ()
--Train of thought: current date + Monday (2nd day of the week) and the difference between the current date and the number of days
The return value of--datepart (weekday,date) is related to @ @datefirst
Set Datefirst 7-or set to American English set language us_english; (Sunday is the first day)
Select DATEADD (Day,2-datepart (Weekday, @date), @date) as ' The next day of the week, Monday '
--Monday, independent of SQL Server language version or @ @datefirst
-' 1900-01-01 ' is Monday, ' 1900-01-01 ' plus (current date vs. 1900-01-01 week) Week
Select DATEADD (Week,datediff (week,0, @date), 0) as ' The Week of Monday '
Go

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.