Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: USAGE OF ROUND AND TRUNC FUNCTIONS

Re: USAGE OF ROUND AND TRUNC FUNCTIONS

From: Holger Baer <holger.baer_at_science-computing.de>
Date: Tue, 15 Feb 2005 11:08:14 +0100
Message-ID: <cushmf$paq$1@news.BelWue.DE>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US