Wednesday, February 20, 2013

MONTHS_BETWEEN Function


In most cases, to find the number of months of experience rather than the number of days. We know that dividing the number of days between two dates by 30 won’t accurately calculate the number of months between those two dates. There- fore, Oracle provides the built-in SQL function MONTHS_BETWEEN for finding the number of months between two dates. MONTHS_BETWEEN is called as follows:

MONTHS_BETWEEN (date1, date2)

The syntax elements are:
date1 Specifies the end of the time period in question. This should be either a DATE value or a string in the default date format.
date2 Specifies the beginning of the time period in question. Like date1, this should also be a DATE value or a string in the default date format.

For Example:

Select MONTHS_BETWEEN('01-JAN-01','01-AUG-01') AS MONTHS_BETWEEN FROM Dual;

No comments:

Post a Comment