 |
|
Oracle round date function tips
Oracle Tips by Burleson Consulting |
The round function is commonly used to round-off
numbers, but you can also use round() with dates. The
round() function returns the date rounded to the format.
In this example, the current date (24 January 2005) is
rounded to the closest month and year:
select
sysdate,
round(sysdate,'month')
month,
round(sysdate,'year') year
from
dual;
SYSDATE MONTH YEAR
--------- --------- ---------
24-JAN-05 01-FEB-05 01-JAN-05
Notice
that SYSDATE is past midmonth so the month was rounded to the next month.
We are not past midyear, however, so the year was rounded to the beginning
of the current year.
 |
If you like Oracle tuning, see the book "Oracle
Tuning: The Definitive Reference", with 950 pages of tuning tips and
scripts.
You can buy it direct from the publisher for 30%-off and get
instant access to the code depot of Oracle tuning scripts. |