Get first day, last day in SQL Server

Source: Internet
Author: User

Get the first and last day of a known year

1. The first day of one months

SELECT DATEADD DATEDIFF (MM,0,getdate0

2. This week's Monday

SELECT DATEADD DATEDIFF (wk,0,getdate0)

3. The first day of the year

SELECT DATEADD DATEDIFF (yy,0,getdate0)

4. First day of the quarter

SELECT DATEADD DATEDIFF (QQ,0,getdate0)

5. The night of the day

SELECT DATEADD DATEDIFF (DD,0,getdate0)

6. Last day of last month

SELECT DateAdd (MS,-3,DATEADDDATEDIFF(mm,0,getdate0

7. Last day of last year

SELECT DateAdd (MS,-3,DATEADDDATEDIFF(yy,0,getdate0

8. Last day of the month

SELECT DateAdd (MS,-3,DATEADDDATEDIFF(M,0,getdate())+1  0))

9. Last day of the year

SELECT DateAdd (MS,-3,DATEADDDATEDIFF(yy,0,getdate())+1  0

10. First Monday of the month

Select DATEADD DATEDIFF (wk,0,dateadd(DD,6-datepart(Day,getdate()), getdate 0)

Related Article

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.