TIME_SLICE

functionsupportedCore SQL functions

docs.snowflake.com ↗

Date & time functions

Calculates the beginning or end of a “slice” of time, where the length of the slice is a multiple of a standard unit of time (minute, hour, day, etc.). This function can be used to calculate the start and end times of fixed-width “buckets” into which data can be categorized.

Syntax

supportedpartialnot supportednot scored

TIME_SLICE( <date_or_time_expr> , <slice_length> , <date_or_time_part> [ , <start_or_end> ] )

Parameters

NameRequiredDescription
date_or_time_exprrequiredThe function returns the start or end of the slice that contains this date or time. The expression must be of type DATE or TIMESTAMP_NTZ.
slice_lengthrequiredThis indicates the width of the slice (i.e. how many units of time are contained in the slice). For example, if the unit is MONTH and the slice_length is 2, then each slice is 2 months wide. The slice_length must be an integer greater than or equal to 1.
date_or_time_partrequiredTime unit for the slice length. The value must be a string containing one of the values listed below: If input expression is a DATE: YEAR, QUARTER, MONTH, WEEK, DAY. If input expression is a TIMESTAMP_NTZ: YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND. The values are case-insensitive.
start_or_endoptionalThis is an optional constant parameter that determines whether the start or end of the slice should be returned. Supported values are ‘START’ or ‘END’. The values are case-insensitive. The default value is ‘START’.

Returns

The data type of the return value is identical to the data type of the input date_or_time_expr (i.e. either TIMESTAMP_NTZ or DATE).

Usage notes

See also