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