TRUNC Function (With Dates)
TRUNC Function (With Dates)
In Oracle/PLSQL, the TRUNC function returns a date truncated to a specific unit of measure.
Syntax
The syntax for the TRUNC function is: TRUNC ( date, [ format ] ) date is the date to truncate. format is the unit of measure to apply for truncating. If the format parameter is omitted, the TRUNC function will truncate the date to the day value, so that any hours, minutes, or seconds will be truncated off. Below are the valid format parameters: Unit Year ISO Year Quarter Month Week IW W Day Valid format parameters SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y IYYY, IY, I Q MONTH, MON, MM, RM WW IW W DDD, DD, J
Start day of the week DAY, DY, D Hour Minute HH, HH12, HH24 MI
Applies To
For Example
The TRUNC function can be used in Oracle/PLSQL. For example: TRUNC(TO_DATE('22-AUG-03'), 'YEAR') TRUNC(TO_DATE('22-AUG-03'), 'Q') TRUNC(TO_DATE('22-AUG-03'), 'MONTH') TRUNC(TO_DATE('22-AUG-03'), 'DDD') TRUNC(TO_DATE('22-AUG-03'), 'DAY') would return '01-JAN-03' would return '01-JUL-03' would return '01-AUG-03' would return '22-AUG-03' would return '17-AUG-03'