QUARTER scalar function

The QUARTER function returns an integer in the range 1–4 that represents the quarter of the year in which the date resides. For example, any dates in January, February, or March return the integer 1.

Read syntax diagramSkip visual syntax diagramQUARTER( expression)

The schema is SYSIBM.

The argument must be an expression that returns one of the following built-in data types: a date, a timestamp, a character string, or a graphic string. If expression is a character or graphic string data type, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a date or timestamp with an actual length of not greater than 255 bytes. For the valid formats of string representations of dates and timestamps, see String representations of datetime values.

If expression is a timestamp with a time zone, or a valid string representation of a timestamp with a time zone, the result is determined from the UTC representation of the datetime value.

The result of the function is a large integer.

The result can be null; if the argument is null, the result is the null value.

Example 1: The following function returns 3 because August is in the third quarter of the year.
   SELECT QUARTER('2008-08-25')
     FROM SYSIBM.SYSDUMMY1
Example 2: Using sample table DSN8C10.PROJ, set the integer host variable QUART to the quarter of the year in which activity number 70 for project 'AD3111' occurred. Activity completion dates are recorded in column ACENDATE.
   SELECT QUARTER(ACENDATE)
     INTO :QUART
     FROM DSN8C10.PROJ
     WHERE PROJNO = 'AD3111' AND ACTNO = 70;
QUART is set to 4.
Example 3: The following invocations of the QUARTER function returns the same result:
SELECT QUARTER('2003-01-02-20.10.05.123456'), 
			QUARTER('2003-01-02-12.10.05.123456-08:00'), 
			QUARTER('2003-01-03-05.10.05.123456+09:00') 
		FROM SYSIBM.SYSDUMMY1;
For each invocation of the QUARTER function in this SELECT statement, the result is 1.

When the input argument contains a time zone, the result is determined from the UTC representation of the input value. The string representations of a timestamp with a time zone in the SELECT statement all have the same UTC representation: 2003-01-02-20.10.05.123456. The month portion of the UTC representation is 1 for January, which is in the first quarter.