SQL statement of Operation Date

Source: Internet
Author: User

1. show the first day of this month <br/> select dateadd (mm, datediff (mm, 0, getdate (), 0) <br/> select convert (datetime, convert (varchar (8), getdate (), <br/> 120) + '01', 120) </P> <p> 2. display the last day of the month <br/> select dateadd (day,-1, convert (datetime, convert <br/> (varchar (8), dateadd (month, 1, getdate (), 120) + '01', 120) <br/> select dateadd (MS,-3, dateadd (mm, datediff (M, 0, getdate () + 1, 0) </P> <p> 3. last day of last month <br/> select dateadd (MS,-3, dateadd (mm, datediff (Mm, 0, getdate (), 0) </P> <p> 4. the first Monday of this month I <br/> select dateadd (wk, datediff (wk, 0, dateadd (DD, 6-datepart (<br/> day, getdate ()), getdate (), 0) </P> <p> 5. the first day of this year <br/> select dateadd (YY, datediff (YY, 0, getdate (), 0) </P> <p> 6. last day of the year <br/> select dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate () + )) </P> <p> 7. last day of last year <br/> select dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate (), 0 )) </P> <p> 8. the first day of this quarter <br/> select Dateadd (QQ, datediff (QQ, 0, getdate (), 0) </P> <p> 9. monday of this week <br/> select dateadd (wk, datediff (wk, 0, getdate (), 0) </P> <p> 10. query records of this month <br/> select * From tablename where datepart (mm, thedate) <br/> = datepart (mm, getdate () and datepart (YY, thedate) <br/> = datepart (YY, getdate () </P> <p> 11. query records of this week <br/> select * From tablename where datepart (wk, thedate) = datepart <br/> (wk, getdate () and datepart (YY, thedate) = Datepart (YY, getdate () </P> <p> 12. query records of the current season. Note: getdate () is a function used to obtain the system time. <Br/> select * From tablename where datepart (QQ, thedate) = datepart <br/> (QQ, getdate () and datepart (YY, thedate) = datepart (YY, getdate () </P> <p> 13. obtain the total number of days of the current month: <br/> select datediff (DD, getdate (), dateadd <br/> (mm, 1, getdate ())) </P> <p> select datediff (day, <br/> dateadd (mm, datediff (mm, '', getdate ()),''), <br/> dateadd (mm, datediff (mm, '', getdate (), '2017-02-01 ') </P> <p> 14. obtain the current day of the week <br/> datename (weekday, getdate () </P> <p>

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.