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