Thursday, January 7, 2016

Get the first day and last day range of the current quarter

Get the first day and last day range of the current quarter:

SELECT
  CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) - 1) QUARTER
, CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) - 0) QUARTER

Get the first day and last day range of the last quarter:

SELECT
  CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) - 2) QUARTER
, CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) - 1) QUARTER

Get the first day and last day range of the next quarter:

SELECT
  CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) + 0) QUARTER
, CAST(MAKEDATE(YEAR(CURDATE()), 1) AS DATETIME) + INTERVAL (QUARTER(CURDATE()) + 1) QUARTER

No comments: