Some useful dates for MS SQL SERVER

Source: Internet
Author: User
Tags getdate

1. The first day of one months
SELECT DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)

2. Monday of this week
SELECT DATEADD (wk, DATEDIFF (Wk,0,getdate ()), 0)

3. The first day of the year
SELECT DATEADD (yy, DATEDIFF (Yy,0,getdate ()), 0)

4. First day of the quarter
SELECT DATEADD (QQ, DATEDIFF (Qq,0,getdate ()), 0)

5. The middle of the day
SELECT DATEADD (DD, DATEDIFF (Dd,0,getdate ()), 0)

6. Last day of last month
SELECT DateAdd (Ms,-3,dateadd (mm, DATEDIFF (Mm,0,getdate ()), 0))

7. Last day of last year
SELECT DateAdd (Ms,-3,dateadd (yy, DATEDIFF (Yy,0,getdate ()), 0))

8. Last day of the month
SELECT DateAdd (Ms,-3,dateadd (mm, DATEDIFF (M,0,getdate ()) +1, 0))

9. The last day of the year
SELECT DateAdd (Ms,-3,dateadd (yy, DATEDIFF (Yy,0,getdate ()) +1, 0 )

10. The first Monday of this month
Select DATEADD (wk, 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.