Other related articles:

Recently viewed articles:

SQL TRUNC Function

SQL TRUNC (date) function is used to round date values. You can mention the degree of precision you want to round up to. The syntax is:

TRUNC (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.

ROUND vs TRUNC:
SQL TRUNC function differs from ROUND in that it always removes extra days from date depending on the precision you want.

Examples:
The following statements illustrate the use of SQL TRUNC function on couple different dates:

SELECT TRUNC (TO_DATE (‘10-OCT-2012’), ‘MM’) FROM DUAL;

OUTPUT:
sql trunc image1

SELECT TRUNC (TO_DATE (‘10-OCT-2012’), ‘YYYY’) FROM DUAL;

OUTPUT:
sql trunc image2                                                                                                

SELECT TRUNC (TO_DATE (‘10-OCT-2012’), ‘DD’) FROM DUAL;

OUTPUT:
sql trunc image3