Skip Headers
Oracle® OLAP DML Reference
10g Release 2 (10.2)

Part Number B14346-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

MONTHS_BETWEEN

The MONTHS_BETWEEN function calculates the number of months between two dates. When the two dates have the same day component or are both the last day of the month, then the return value is a whole number. Otherwise, the return value includes a fraction that considers the difference in the days based on a 31-day month. The return value is positive when the first date is later than the second date, and negative when the first date is earlier than the second date.

Return Value

NUMBER

Syntax

MONTHS_BETWEEN(datetime_expression1datetime_expression2)

Arguments

datetime-expression1

One expression that has the DATETIME data type, or a text expression that specifies a date.

datetime-expression2

A second expression that has the DATETIME data type, or a text expression that specifies a date.

Examples

Example 18-6 Calculating the Number of Months Between Dates

The following statement calculates the number of months between March 26, 2004, and July 6, 2001.

SHOW months_between('06Jul2005' '17Jul2003')
23.65

Example 18-7 Last Days

The return value is a whole number when both dates are the last day of the month.

SHOW months_between('29Feb2000', '30Sep2000')
-7.00