Bug #54626 DATE_FORMAT() should have a format for Quarter
Submitted: 19 Jun 2010 1:02 Modified: 19 Jun 2010 8:07
Reporter: Bill Karwin (Candidate Quality Contributor) (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S4 (Feature request)
Version:5.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: date, format, FUNCTION, qc

[19 Jun 2010 1:02] Bill Karwin
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
[19 Jun 2010 8:07] Valeriy Kravchuk
Thank you for the feature request.