Caché SQL Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

A date function that returns the quarter of the year as an integer for a date expression.
{fn QUARTER(date-expression)}
date-expression An expression that is the name of a column, the result of another scalar function, or a date or timestamp literal.
QUARTER returns an integer from 1 to 4. The quarter is calculated for a Caché date integer, a $HOROLOG or $ZTIMESTAMP value, an ODBC format date string, or a timestamp.
A date-expression timestamp is data type %Library.TimeStamp (yyyy-mm-dd hh:mm:ss.fff).
The time portion of the timestamp is not evaluated and can be omitted. The date-expression can also be specified as data type %Library.FilemanDate, %Library.FilemanTimestamp, or %MV.Date.
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 evaluates only the month portion of a datetime string. QUARTER does not perform value or range checking for user-supplied values. Invalid month values are returned as follows: month=0 returns 1; month > 12 returns 4.
The same quarter information can be returned by using the DATEPART or DATENAME function. DATEPART and DATENAME performs value and range checking on the full date string. 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() method call:
The following examples both return the number 1 because the date (February 25) is in the first quarter of the year:
SELECT {fn QUARTER('2004-02-25')} AS Q_Given
SELECT {fn QUARTER(59590)} AS Q_Given
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