TRUNC
Description
The TRUNC function is used to truncate the date expression expr
according to the specified fmt
format, returning a new date.
Parameter Description
- expr (date): The date expression to be truncated.
- fmt (string): A string used to specify the truncation precision, case insensitive. Valid values are as follows:
- 'YEAR', 'YYYY', 'YY': Truncate to the first day of the year in which
expr
is located (January 1st). - 'QUARTER': Truncate to the first day of the quarter in which
expr
is located. - 'MONTH', 'MM', 'MON': Truncate to the first day of the month in which
expr
is located. - 'WEEK': Truncate to the Monday of the week in which
expr
is located.
- 'YEAR', 'YYYY', 'YY': Truncate to the first day of the year in which
Return Result
Returns a date value representing the date truncated according to the specified fmt
.
Usage Example
Notes
- When expr is not a valid date expression, the TRUNC function will return NULL.
- When the fmt parameter is incorrect, the TRUNC function will return an error. Please ensure to use a valid fmt value.