QUARTER
QUARTER(date)
Section titled “QUARTER(date)”- date: The date parameter in the QUARTER(date) function for MySQL signifies the date from which the quarter of the year is to be extracted. It must be a valid date in the format “YYYY-MM-DD”, “YYYYMMDD”, “YYMMDD” or a year in string format like “YYYY”. The quarter is returned as an integer in the range from 1 to 4, with 1 representing the first quarter of the year (January, February, March) and 4 representing the last quarter of the year (October, November, December).
Example
Section titled “Example”SELECT QUARTER('2021-07-18');Output
Section titled “Output”3Explanation
Section titled “Explanation”The QUARTER function in MySQL returns the quarter of the year for a date. The input date ‘2021-07-18’ falls in the third quarter of the year, therefore the output is 3.
QUARTER(date)
Section titled “QUARTER(date)”- date: It is the date value from which the quarter of the year is to be extracted. This could be a date column in a table or an explicitly input date. It must be a valid expression and data of type date or datetime. The function will return an integer representing the quarter for the provided date ranging from 1 to 4.
Example
Section titled “Example”SELECT DATEPART(QUARTER, '2022-03-15') AS QuarterOfYear;Output
Section titled “Output”| QuarterOfYear || ------------- || 1 |Explanation
Section titled “Explanation”In SQL Server, the DATEPART() function is used to extract parts from a date. The example code extracts the quarter from a given date (‘2022-03-15’). The output is ‘1’, which indicates the first quarter of the year.
QUARTER(date)
Section titled “QUARTER(date)”- date: The parameter refers to a valid date value for which to identify the calendar quarter. It must be a DATE or TIMESTAMP data type. Should the date parameter be omitted or null, then the current date and time will be used as the default value.
Example
Section titled “Example”SELECT EXTRACT(QUARTER FROM DATE '2012-08-08') "Quarter"FROM DUAL;Output
Section titled “Output”Quarter-------3Explanation
Section titled “Explanation”The EXTRACT(QUARTER FROM DATE '2012-08-08') function returns the quarter of the year (from 1 to 4) for the specified date. Here it returns 3 since August falls in the third quarter of the year.