http://blog.csdn.net/cleanfield/article/details/41447585
Compiled SQL code, all executable
- #当年第一天:
- 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 );
- #当前The first day of month:
- SELECT concat (Date_format (Last_day (now ()),'%y-%m-'),' 01 ');
- #当前The last day of month:
- SELECT Last_day (now ());
- #前一The first day of month:
- SELECT concat (Date_format (Last_day (now ()-Interval 1 month), '%y-%m-'),' 01 ');
- #前一The last day of month:
- SELECT Last_day (now ()-Interval 1 month);
- #前两The first day of month:
- SELECT concat (Date_format (Last_day (now ()-Interval 2 month), '%y-%m-'),' 01 ');
- #前两The last day of 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);
0919MYSQL take the first and last day of the current week/month/quarter/year