Obtain the first and last days in SQL Server.

Source: Internet
Author: User

The first and last days of a known year are obtained in the project. I think the network is good and I will leave it as a backup.
1. The first day of a month

  • Select dateadd (mm, datediff (mm, 0, getdate (), 0)
  • 2. Monday of the 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. The first day of the quarter

  • Select dateadd (QQ, datediff (QQ, 0, getdate (), 0)
  • 5. midnight 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.