Trunc will chops off the date to which it was equal to or less than the
given date.
Syntax: trunc (date, (day |
month | year))
Ø If the second
parameter was year then it always
returns the first day of the current year.
Ø If the second
parameter was month then it always
returns the first day of the current month.
Ø If the second
parameter was day then it always
returns the previous sunday.
Ø If the second
parameter was null then it returns nothing.
Ø If the you are
not specifying the second parameter then trunk will resets the time to the begining
of the current day.
Ex:
SQL> select trunc(to_date('24-dec-04','dd-mon-yy'),'year'),
trunc(to_date('11-mar-
06','dd-mon-yy'),'year') from
dual;
TRUNC(TO_
TRUNC(TO_
------------- --------------
01-JAN-04 01-JAN-06
SQL> select
trunc(to_date('11-jan-04','dd-mon-yy'),'month'), trunc(to_date('18-jan-
04','dd-mon-yy'),'month') from dual;
TRUNC(TO_
TRUNC(TO_
------------- -------------
01-JAN-04 01-JAN-04
SQL> select
trunc(to_date('26-dec-06','dd-mon-yy'),'day'), trunc(to_date('29-dec-
06','dd-mon-yy'),'day') from dual;
TRUNC(TO_ TRUNC(TO_
------------- --------------
24-DEC-06
24-DEC-06
SQL> select to_char(trunc(to_date('24-dec-06','dd-mon-yy')), 'dd mon
yyyy hh:mi:ss
am') from dual;
TO_CHAR(TRUNC(TO_DATE('
---------------------------------
24 dec 2006
12:00:00 am