MySQL QUARTER() function
QUARTER() function
MySQL QUARTER() returns the quarter of the year for a date. The return value is in the range of 1 to 4. It provides a way to identify the quarter in which a date falls, facilitating various date-related calculations and data categorization.
This function is useful in -
- QUARTER() is essential for identifying the season or part of the year in which an event or activity occurs.
- The function is valuable for tracking progress toward goals set for specific quarters.
- QUARTER() is used to make seasonal adjustments to data to account for quarter-specific trends.
- QUARTER() is valuable for categorizing dates into specific quarters, aiding in data organization and analysis.
- QUARTER() is useful in financial forecasting, where data is projected for specific quarters.
- The function supports trend analysis by allowing data to be grouped and analyzed by quarters.
- QUARTER() helps aggregate data by quarter, enabling summary analysis over distinct periods.
Syntax:
QUARTER(date);
Where date1 is a date.
Syntax Diagram:
MySQL Version: 8.0
Pictorial Presentation:
Example: MySQL QUARTER() function
The following statement will return a value between 1 to 4 as a QUARTER of a year for a given date 2009-05-18.
Code:
SELECT QUARTER('2009-05-18');
Output:
mysql> SELECT QUARTER('2009-05-18'); +-----------------------+ | QUARTER('2009-05-18') | +-----------------------+ | 2 | +-----------------------+ 1 row in set (0.01 sec)
Example: QUARTER() function using table
The following statement will return a value between 1 to 4 as a QUARTER of a year for ord_date from the table purchase making sure that the ord_date belongs to the 2nd QUARTER.
Sample table: purchase
Code:
SELECT invoice_no,ord_date,QUARTER(ord_date)
FROM purchase
WHERE QUARTER(ord_date)=2 ;
Output:
mysql> SELECT invoice_no,ord_date,QUARTER(ord_date) -> FROM purchase -> WHERE QUARTER(ord_date)=2 ; +------------+------------+-------------------+ | invoice_no | ord_date | QUARTER(ord_date) | +------------+------------+-------------------+ | INV0005 | 2007-06-25 | 2 | +------------+------------+-------------------+ 1 row in set (0.00 sec)
Video Presentation:
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
Previous: PERIOD_DIFF()
Next: SEC_TO_TIME()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/date-and-time-functions/mysql-quarter-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics