TRUNC_UDF (TIMESTAMP_LTZ, VARCHAR)

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Definition

This user-defined function (UDF) reproduces the Teradata and Oracle TRUNC(Date) functionality when the format parameter is specified.

TRUNC_UDF(DATE_TO_TRUNC TIMESTAMP_LTZ, DATE_FMT VARCHAR(5))

Parameters

DATE_TO_TRUNC TIMESTAMP_LTZ

A timestamp_ltz value to truncate which must be a date, timestamp, or timestamp with timezone.

DATE_FMT VARCHAR

A varchar value that should be one of the date formats supported by the trunc function.

Returns

Returns a date truncated using the format specified.

Usage example

Input:

SELECT TRUNC_UDF(TIMESTAMP '2015-08-18 12:30:00', 'Q')

Output:

2015-07-01

Last updated