Skip to main content
Previous sectionNext section


A time function that returns the minute for a datetime expression.


{fn MINUTE(time-expression)}


Argument Description
time-expression An expression that is the name of a column, the result of another scalar function, or a string or numeric literal. It must resolve either to a datetime string or a time integer, where the underlying data type can be represented as %Time, %TimeStamp, or %PosixTime.


MINUTE returns an integer specifying the minutes for a given time or datetime value. Minutes are calculated for a $HOROLOG or $ZTIMESTAMP value, an ODBC format date string, or a timestamp.

A time-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).

To change the default time format, use the SET OPTION command.

Note that you can supply a time integer (number of elapsed seconds), but not a time string (hh:mm:ss). You must supply a datetime string (yyyy-mm-dd hh:mm:ss). The date portion of the datetime string is not validated; the year can be in the range 0001 through 9999.

You can omit the seconds (:ss) portion of a datetime string and still return the minutes portion.

The minutes (mm) portion should be an integer in the range from 0 through 59. There is, however, no range checking for user-supplied values. Numbers greater than 59, negative numbers and fractions are returned as specified. Leading zeros are optional on input; leading zeros are suppressed on output.

MINUTE returns zero minutes when the minutes portion is '0', '00', or a nonnumeric value. Zero minutes is also returned if no time expression is supplied, or the minutes portion of the time expression is omitted entirely ('hh', 'hh:', 'hh::', or 'hh::ss'), or if the time expression format is invalid.

The same time information can be returned using DATEPART or DATENAME.

This function can also be invoked from ObjectScript using the MINUTE() method call:



The following examples both return the number 45 because it is the forty-fifth minute of the time expression in the datetime string:

SELECT {fn MINUTE('2018-02-16 18:45:38')} AS Minutes_Given
Copy code to clipboard
SELECT {fn MINUTE(67538)} AS Minutes_Given
Copy code to clipboard

The following example also returns 45. As shown here, the seconds portion of the time value can be omitted:

SELECT {fn MINUTE('2018-02-16 18:45')} AS Minutes_Given
Copy code to clipboard

The following example returns 0 minutes because the time expression has been omitted from the datetime string:

SELECT {fn MINUTE('2018-02-16')} AS Minutes_Given
Copy code to clipboard

The following examples all return the minutes portion of the current time:

       {fn MINUTE({fn CURTIME()})} AS Min_CurT,
       {fn MINUTE({fn NOW()})} AS Min_Now,
       {fn MINUTE($HOROLOG)} AS Min_Horolog,
Copy code to clipboard

The following example shows that leading zeros are suppressed. The first MINUTE function returns a length 2, the others return a length of 1. An omitted time is considered to be 0 minutes, which has a length of 1:

SELECT LENGTH({fn MINUTE('2018-02-22 11:45:00')}),
       LENGTH({fn MINUTE('2018-02-22 03:05:00')}),
       LENGTH({fn MINUTE('2018-02-22 3:5:0')}),
       LENGTH({fn MINUTE('2018-02-22')})
Copy code to clipboard

The following Embedded SQL example shows that the MINUTE function recognizes the TimeSeparator character specified for the locale:

  DO ##class(%SYS.NLS.Format).SetFormatItem("TimeSeparator",".")
  &sql(SELECT {fn MINUTE('2018-02-22 18.45.38')}
  INTO :a)
  WRITE "minutes=",a
Copy code to clipboard

See Also