Posts

Showing posts with the label MONTHS BETWEEN

Let's review MONTHS_BETWEEN!

Image
MONTHS_BETWEEN Syntax: MONTHS_BETWEEN (start date, end date) Parameters: start date and end date are the dates which are used to calculate number of months between. Return type: The MONTHS_BETWEEN function returns a numeric value. Usage: HR manager decided to give different Christmas gifts to the employees of the company based on the number of years they have spent in the organization. Manager to Data analyst: Bring me the list of all the employees and approximately how many years they have spent with the organization. Data analyst runs below query to fetch the required data. SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME,  ROUND( MONTHS_BETWEEN (SYSDATE, HIRE_DATE)/12) AS NO_OF_YEARS  FROM EMPLOYEES;