Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

MONTHS_BETWEEN function (extension)

Syntax

MONTHS_BETWEEN ( date_expression, date_expression )

Description

The scalar function MONTHS_BETWEEN computes the number of months between two date values corresponding to the first and second arguments.

Example

SELECT MONTHS_BETWEEN (SYSDATE, order_date)

FROM orders

WHERE order_no = 1002 ;

Notes

  • The first and the second arguments to the function must be of type DATE.
  • The result is of type INTEGER.
  • The result is negative if the date corresponding to the second argument is greater than that corresponding to the first argument.
  • If any of the arguments expression evaluates to null, the result is null.

TOCIndex