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.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.036 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.