MySQL operation time

Source: Internet
Author: User

Select Curdate (); --Get the current date
Select Last_day (Curdate ()); -Get the last day of the month.
Select Date_add (Curdate (), Interval-day (Curdate ()) +1 day); -Get the first day of the month
Select Date_add (Curdate ()-day (Curdate ()) +1,interval 1 month); --Get the first day of next month
Select DATEDIFF (Date_add (Curdate ()-day (Curdate ()) +1,interval 1 month), Date_add (Curdate (), Interval-day (Curdate ()) + 1 day)) from dual; --Get the number of days of the current month

#当年第一天:
SELECT date_sub (Curdate (), INTERVAL DayOfYear (Now ()) – 1 day);

#当年最后一天:
SELECT concat (now ()), '-12-31 ');

#当前week的第一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ()) + 1 day);

#当前week的最后一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ())-5 day);

#前一week的第一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ()) + 8 day);

#前一week的最后一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ()) + 2 day);

#前两week的第一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ()) + day);

#前两week的最后一天:
Select Date_sub (Curdate (), INTERVAL WEEKDAY (Curdate ()) + 9 day);

#当前month的第一天:
SELECT concat (Date_format (Last_day (now ()), '%y-%m-'), ' 01 ');

#当前month的最后一天:
SELECT Last_day (now ());

#前一month的第一天:
SELECT concat (Date_format (Last_day (now ()-interval 1 month), '%y-%m-'), ' 01 ');

#前一month的最后一天:
SELECT Last_day (now ()-interval 1 month);

#前两month的第一天:
SELECT concat (Date_format (Last_day (now ()-Interval 2 month), '%y-%m-'), ' 01 ');

#前两month的最后一天:
SELECT Last_day (now ()-interval 2 month);

#当前quarter的第一天:
Select Concat (Date_format (Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-3 month), '%y-%m-'), ' 01 ');

#当前quarter的最后一天:
Select Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-1 month);

#前一quarter的第一天:
Select Concat (Date_format (Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-6 month), '%y-%m-'), ' 01 ');

#前一quarter的最后一天:
Select Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-4 month);

#前两quarter的第一天:
Select Concat (Date_format (Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-9 month), '%y-%m-'), ' 01 ');

#前两quarter的最后一天:
Select Last_day (Makedate (EXTRACT (year from Curdate ()), 1) + Interval QUARTER (curdate ()) *3-7 month);

MySQL operation time

Related Article

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.