MySQL obtains start_date/end_date_MySQL of the current week, month, and quarter.

Source: Internet
Author: User
MySQL obtains the start_dateend_date bitsCN.com of the current week, month, and quarter.

MySQL obtains start_date/end_date of the current week, month, and quarter.

The first day of the current week:

Select date_sub (curdate (), interval weekday (curdate () + 1 DAY)

The last day of the current week:

Select date_sub (curdate (), interval weekday (curdate ()-5 DAY)

The first day of the previous week:

Select date_sub (curdate (), interval weekday (curdate () + 8 DAY)

Last day of the previous week:

Select date_sub (curdate (), interval weekday (curdate () + 2 DAY)

First day of the first two week:

Select date_sub (curdate (), interval weekday (curdate () + 15 days)

The last day of the first two week:

Select date_sub (curdate (), interval weekday (curdate () + 9 DAY)

The first day of the current month:

SELECT concat (date_format (LAST_DAY (now (), '% Y-% m-'), '01 ')

The last day of the current month:

SELECT LAST_DAY (now ())

The first day of the previous month:

SELECT concat (date_format (LAST_DAY (now ()-interval 1 month), '% Y-% m-'), '01 ')

Last day of the previous month:

SELECT LAST_DAY (now ()-interval 1 month)

First day of the first two months:

SELECT concat (date_format (LAST_DAY (now ()-interval 2 month), '% Y-% m-'), '01 ')

The last day of the first two months:

SELECT LAST_DAY (now ()-interval 2 month)

The first day of the current quarter:

Select concat (date_format (LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-3 month ), '% Y-% m-'), '01 ')

Last day of the current quarter:

Select LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-1 month)

The first day of the previous quarter:

Select concat (date_format (LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-6 month ), '% Y-% m-'), '01 ')

Last day of the previous quarter:

Select LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-4 month)

The first two quarter's first day:

Select concat (date_format (LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-9 month ), '% Y-% m-'), '01 ')

Last day of the first two quarter:

Select LAST_DAY (MAKEDATE (EXTRACT (year from curdate (), 1) + interval QUARTER (CURDATE () * 3-7 month)

BitsCN.com

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.