Description:
The DATE_FORMAT() function is missing a format control to get the Quarter from a date. This makes it awkward to parameterize
MySQL supports a builtin function QUARTER() as part of the collection of functions to extract components from dates. Most date components are supported as format controls in the DATE_FORMAT() function, but Quarter is not supported.
How to repeat:
Extract a variety of different formats from a date:
SELECT
DATE_FORMAT(NOW(), '%Y') AS Year,
DATE_FORMAT(NOW(), '%Y/%m') AS Month,
DATE_FORMAT(NOW(), '%X, week %V') AS Week,
DATE_FORMAT(NOW(), '%Y/%m/%d') AS Day,
CONCAT(YEAR(NOW()), ', Q', QUARTER(NOW())) AS Quarter;
One of these expressions is not like the other! :-)
Suggested fix:
Add control formats for Quarter.
Suggest %q to render as a simple numeric value between 1 and 4.
Suggest %Q to render as 'Q' followed by a numeric value between 1 and 4.
Desired usage:
SELECT
DATE_FORMAT(NOW(), '%Y, Quarter %q') AS QuarterLong,
DATE_FORMAT(NOW(), '%Y, %Q') AS QuarterShort;
Desired result:
2010, Quarter 2
2010, Q2