In this guide, we will explain how to use the MySQL QUARTER function with syntax and examples.
Description
The MySQL QUARTER function returns the quarter portion of a date value.
Syntax
The syntax for the QUARTER function in MySQL is:
QUARTER( date_value )
Parameters or Arguments
date_value
A date or datetime value from which to extract the quarter.
Note
- The QUARTER function returns the quarter (a number from 1 to 4) given a date value.
- Dates that have a month of Jan-Mar would return 1.
- Dates that have a month of Apr-Jun would return 2.
- Dates that have a month of Jul-Sep would return 3.
- Dates that have a month of Oct-Dec would return 4.
- See also the EXTRACT, YEAR, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, and MICROSECOND functions.
Applies To
The QUARTER function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some QUARTER function examples and explore how to use the QUARTER function.
For example:
mysql> SELECT QUARTER('2014-01-28'); Result: 1 mysql> SELECT QUARTER('2014-01-28 15:21:05'); Result: 1 mysql> SELECT QUARTER('2013-04-20'); Result: 2 mysql> SELECT QUARTER('2013-07-16'); Result: 3 mysql> SELECT QUARTER('2013-10-15'); Result: 4
This last QUARTER example would display the quarter portion of the current system date (current system date is returned by the CURDATE function).
mysql> SELECT QUARTER(CURDATE());
Next Topic : Click Here
Pingback: MySQL: PERIOD_DIFF Function | Adglob Infosystem Pvt Ltd