The first and last days of a date

Source: Internet
Author: User

Declare @ tmpdate datetime
Select @ tmpdate = dateadd (week, 2, '2017-08-26 ')
Select @ tmpdate = getdate ()

-- Select datepart (weekday, @ tmpdate)
-- The first day of a week (the first day of a week on Monday ):
Select dateadd (day,-datepart (weekday, @ tmpdate) + 2, @ tmpdate)
-- The last day of a week (the first day of a week on Monday ):
Select dateadd (day, 8-datepart (weekday, @ tmpdate), @ tmpdate)
-- The first day of the month
Select dateadd (day,-day (@ tmpdate) + 1, @ tmpdate)
-- The last day of the month (note that the first day of the month in the next month is the last day of the month)
Select dateadd (day,-day (dateadd (m, 1, @ wDate), dateadd (m, 1, @ wDate ))

-- The first day of the season
Select dateadd (qq, DATEDIFF (qq, 0, getdate (), 0)
-- The first day of the year
Select dateadd (yy, DATEDIFF (yy, 0, getdate (), 0)

 

-- Calculate the number of days on January 1, January.

Select date = @ tmpdate, days = 32-day (@ tmpdate + 32-day (@ tmpdate ))

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.