Mysql _ date increase/decrease problems

Source: Internet
Author: User
Mysql _ date increase and decrease problems selectcurdate ();??????????? # Obtain the current date selectlast_day (curdate ());?????????? # Obtain the last day of the current month. SelectDATE_ADD (curdate (), interval-day (curdate () + 1day );? # Obtain selectdate_add (curdate

Mysql _ date increase/decrease problem select curdate ();? ? ? ? ? ? ? ? ? ? ? # Obtain the current date select last_day (curdate ());? ? ? ? ? ? ? ? ? ? # Obtain the last day of the current month. Select DATE_ADD (curdate (), interval-day (curdate () + 1 day );? # Obtain the first day of this month select date_add (curdate

Mysql _ date increase or decrease

Select curdate ();? ? ? ? ? ? ? ? ? ? ? # Getting the current date

Select last_day (curdate ());? ? ? ? ? ? ? ? ? ? # Obtain the last day of the current month.

Select DATE_ADD (curdate (), interval-day (curdate () + 1 day );? # Obtain the first day of the month

Select date_add (curdate ()-day (curdate () + 1, interval 1 month); # obtain the first day of the next month

Select date_add (curdate ()-day (curdate () + 1, interval-1 month); # obtain the first day of the last month

?

However, since the number of days in each month varies from 28/29 to 30 to 31, how can this problem be used? -Day (: stocktime) + 1 to obtain the last month or 1st day of next month may cause problems

As follows:

DATE_ADD (: stocktime, interval-1 month), interval-day (: stocktime) + 1 day)

CONCAT (DATE_FORMAT (DATE_ADD (: stocktime, interval-1 month), '% y-% m'),'-01 ')

Should be changed:

DATE_ADD (: stocktime, interval-day (: stocktime) + 1 day)

CONCAT (DATE_FORMAT (: stocktime, '% y-% m'),'-01 ')

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.