Round Dates



ROUND

Syntax: ROUND ( source date [, date precision format ] )

Parameters: source date is the date which is to be rounded. Data precision format is the unit of measure to apply for rounding. It is an optional parameter. If date precision format is omitted, the round function will round to the nearest day. Date precision formats include century (CC), year (YYYY), quarter (Q), month (MM), week (W), day (DD), hour (HH), and minute (MI).

Return Type: The ROUND function (as it applies to dates) returns date value.

Usage: According to company's policy, every month employees get shopping coupons. For the employees who have joined the organization after 15th of the month will start getting their shopping coupons from the next month. Manager wants the months from which employees get their shopping coupons. Manager to Data analyst: Bring me the list of all employees with the month from which employee is getting their shopping coupons. Data analyst runs below query to fetch the required data.

SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, TO_CHAR ( ROUND ( TO_DATE ( HIRE_DATE, 'DD-MON-RR'), 'MONTH' ), 'MON') FROM EMPLOYEES;



Comments

Popular posts from this blog

Let's learn Cross Join!

Full Outer Join!

Let's extract STRING!