Skip to main content


A date function that returns the quarter of the year as an integer for a date expression.


{fn QUARTER(date-expression)}


QUARTER returns an integer from 1 to 4. The quarter is calculated for an InterSystems IRIS date integer, a $HOROLOG or $ZTIMESTAMP value, an ODBC format date string, or a timestamp.

A date-expression timestamp can be either data type %Library.PosixTimeOpens in a new tab (an encoded 64-bit signed integer), or data type %Library.TimeStampOpens in a new tab (yyyy-mm-dd hh:mm:ss.fff).

The time periods for the four quarters are as follows:

Quarter Period (inclusive)
1 January 1 to March 31 (90 or 91 days)
2 April 1 to June 30 (91 days)
3 July 1 to September 30 (92 days)
4 October 1 to December 31 (92 days)

QUARTER is based on the month portion of a datetime string. However, all of date-expression is validated and must include a month within the range 1 through 12 and a valid day value for the specified month and year. Otherwise, an SQLCODE -400 error <ILLEGAL VALUE> is generated. The time portion of date-expression can be omitted, but if present must be valid.

The same quarter information can be returned by using the DATEPART or DATENAME function. You can use the DATEADD or TIMESTAMPADD function to increment a date by a specified number of quarters.

This function can also be invoked from ObjectScript using the QUARTER()Opens in a new tab method call:




An expression that is the name of a column, the result of another scalar function, or a date or timestamp literal.


The following examples both return the number 1 because the date (February 22) is in the first quarter of the year:

SELECT {fn QUARTER('2018-02-22')} AS ODBCDateQ
SELECT {fn QUARTER(64701)} AS HorologDateQ

The following examples all return the current quarter:

SELECT {fn QUARTER({fn NOW()})} AS Q_Now,
       {fn QUARTER($ZTIMESTAMP)} AS Q_ZTstamp,
       {fn QUARTER($HOROLOG)} AS Q_Horolog

See Also

FeedbackOpens in a new tab