DATE_TRUNC
Date function
Description
The DATE_TRUNC function truncates a timestamp expression or literal based on the date part that you specify, such as hour, day, or month.
In Snowflake this function truncates a DATE, TIME, or TIMESTAMP value to the specified precision.
Valid <datepart> in Snowflake:
microsecond, microseconds
millisecond, milliseconds
second, seconds
minute, minutes
hour, hours
day, days
week
month, months
quarter, quarters
year, years
Invalid formats in Snowflake:
Weeks
decade, decades
century, centuries
millennium, millennia
This function is fully supported in Snowflake.
For more information about quoted identifiers in functions, click here.
Grammar Syntax
Sample Source Patterns
Supported date parts
Input Code:
Output Code:
Invalid date parts
This transformation is performed in order to emulate Redshift behavior for the following date parts
decade, decades
century, centuries
millennium, millennia
Input Code:
Output Code:
For more information please refer to the following documentation in Snowflake:
Known Issues
In Amazon Redshift, the default precision for timestamps is 6 digits (microseconds), while in Snowflake, the default precision is 9 digits (nanoseconds). Due to these differences in precision, it’s important to consider your specific needs when working with timestamps. If you require different precision in either platform, you can use the following options.
Use ALTER SESSION:
Please note that depending on the data type used to store the value obtained with DATE_TRUNC(), there may be limitations in precision that could result in a loss of accuracy.
Related EWIs
There are no known issues.
Last updated