Skip to main content

QUARTER

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

Synopsis

{fn QUARTER(date-expression)}

Arguments

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

Description

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.TimeStampOpens in a new tab (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()Opens in a new tab method call:

$SYSTEM.SQL.QUARTER(date-expression)

Examples

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(CURRENT_DATE)} AS Q_CurrD,
       {fn QUARTER(CURRENT_TIMESTAMP)} AS Q_CurrTstamp,
       {fn QUARTER($ZTIMESTAMP)} AS Q_ZTstamp,
       {fn QUARTER($HOROLOG)} AS Q_Horolog

See Also

FeedbackOpens in a new tab