Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: USAGE OF ROUND AND TRUNC FUNCTIONS
Arijit Chatterjee wrote:
> Dear Sir,
> As per your instruction I run the queries and got these
> outpous.Here truct return the same year but round next.
> But my question was what is the usage of these two functions.
> Through this outputs still I am not clear.
>
> SQL> SELECT trunc (TO_DATE ('27-oct-05'),'YEAR')
> 2 "New Year" FROM DUAL;
> /c clsNew Year
> ---------
> 01-JAN-05
>
> SQL> SELECT round (TO_DATE ('27-oct-05'),'YEAR')
> 2 "New Year" FROM DUAL;
> /c clsNew Year
> ---------
> 01-JAN-06
>
> Regards
> Arijit Chatterjee
trunc (the_date, 'YEAR') gives you the first day of the year of a given date, whereas round (the_date, 'YEAR') gives the nearest first day which might well be the one of the following year.
When to use them? When you need them of course ;-)
E.g. if trunc(the_date, 'YEAR') and round (the_date,'YEAR') give different results, you know that you are in the second half of the year.
HTH
Holger
Received on Tue Feb 15 2005 - 04:08:14 CST