Inquiries at the beginning of the year, at the end of last years, early next year with the year-end SQL statement

Source: Internet
Author: User


--Annual calculation

DECLARE @date datetime
Set @date =getdate ()
--the first day of the year on which the given date is calculated
Select DATEADD (Year,datediff (year,0, @date), 0) as ' the first day of the year '
-Year-End, calculate the last day of the year for a given date
Select DATEADD (Year,datediff (year,-1, @date), -1) as ' The last day of the year '
--At the beginning of the previous year, calculate the first day of the Year of the year in which the given date
Select DATEADD (Year,datediff (year,-0, @date) -1,0) as ' the first day of the Year of the Year '
--At the end of the previous year, calculate the last day of the Year of the year in which the given date
Select DATEADD (Year,datediff (year,0, @date), -1) as ' The last day of the previous year of the Year '
--At the beginning of the next year, calculate the first day of the Year of the year in which the given date is
Select DATEADD (Year,1+datediff (year,0, @date), 0) as ' the first day of the next year of the Year '
--At the end of the next year, calculate the last day of the year in which the given date is located
Select DATEADD (Year,1+datediff (year,-1, @date), -1) as ' The last day of the next year of the Year '
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.