Home / InterSystems SQL Reference / SQL Functions / QUARTER

InterSystems SQL Reference
Previous section           Next section
InterSystems: The power behind what matters   

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 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.PosixTime (an encoded 64-bit signed integer), or 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 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 22) is in the first quarter of the year:
SELECT {fn QUARTER('2018-02-22')} AS Q_Given
SELECT {fn QUARTER(64701)} 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

Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-07-23 05:23:52