SQL ROUND Function
SQL ROUND (date) function is used to round date values. You can mention the degree of precision you want to round up to. The syntax is:
ROUND (date, round_to);
Second parameter (round_to) defines the degree of precision you want to round this date to. Date value can be rounded to day (‘DD’), month (‘MM’), year (‘YYYY’) and so on. If you don’t pass any value for second parameter, it will remove all values for timestamp, only date will be returned.
Examples:
The following statements illustrate the use of SQL ROUND function on couple different dates:
SELECT ROUND (TO_DATE (‘10-OCT-2012’), ‘MM’) FROM DUAL;
OUTPUT:
SELECT ROUND (TO_DATE (‘10-OCT-2012’), ‘YYYY’) FROM DUAL;
OUTPUT:
SELECT ROUND (TO_DATE (‘10-OCT-2012’), ‘DD’) FROM DUAL;
OUTPUT:
Note: The sql round function uses the following rules:
For ‘MM’: If date is before or equal to 15th of month, it will be rounded to first day of month, otherwise to first day of next month.
For ‘YYYY’: If date is before or equal to June 30th, it will be rounded to first day of year, otherwise to first day of next year.